CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 2010

Similar documents
CS 102 / CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2010

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 2009

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

CS 102/107 - Introduction to Programming Midterm Exam #2 - Prof. Reed Spring 2011

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring What is your name?: (4 points for writing it on your answer sheet)

I. True/False: (2 points each) On your bubble form fill out a for true and b for false.

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall What is your name?: (3 points for writing it on your answer sheet)

I. True/False: (2 points each)

I. True/False: (2 points each)

I. True/False: (2 points each)

I. True/False: (2 points each)

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 03

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

CS 177 Week 15 Recitation Slides. Review

COE 212 Engineering Programming. Welcome to Exam I Tuesday November 11, 2014

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

IT Introduction to Programming for I.T. Midterm Exam #1 - Prof. Reed Spring 2008

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Term 1 Unit 1 Week 1 Worksheet: Output Solution

COE 212 Engineering Programming. Welcome to Exam II Monday May 13, 2013

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

Midterm Exam CS 251, Intermediate Programming March 12, 2014

C: How to Program. Week /Mar/05

Practice Midterm 1. Problem Points Score TOTAL 50

Some Practice Midterm Problems

Object-Oriented Programming

Question: Total Points: Score:

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2017

Chapter 2 - Introduction to C Programming

Section 004 Spring CS 170 Exam 1. Name (print): Instructions:

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Ex: If you use a program to record sales, you will want to remember data:

Control Structures in Java if-else and switch

CS 251L Review Quiz Key

CMPS 12A Winter 2006 Prof. Scott A. Brandt Final Exam, March 21, Name:

CSCE 206: Structured Programming in C++

Building Java Programs. Chapter 2: Primitive Data and Definite Loops

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

COE 212 Engineering Programming. Welcome to Exam II Thursday April 21, Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F.

CS 170 Exam 1. Version: B Fall Name (as on OPUS):

CIS 110 Introduction to Computer Programming. February 29, 2012 Midterm

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

King Saud University College of Computer and Information Sciences Computer Science Department

CS 170 Exam 1. Version: C Fall Name (as on OPUS):

CS 302: INTRODUCTION TO PROGRAMMING. Lectures 7&8

Midterm Review Session

CS212 Midterm. 1. Read the following code fragments and answer the questions.

Oct Decision Structures cont d

Course Outline. Introduction to java

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Topic 4 Expressions and variables

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

CS 312 Midterm 1 Spring 2013

COMP-202: Foundations of Programming. Lecture 3: Boolean, Mathematical Expressions, and Flow Control Sandeep Manjanna, Summer 2015

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

Programming Basics. Digital Urban Visualization. People as Flows. ia

CSCE 145 Exam 1 Review Answers. This exam totals to 100 points. Follow the instructions. Good luck!

CS 101 Spring 2007 Midterm 2 Name: ID:

Faculty of Science COMP-202A - Foundations of Computing (Fall 2013) - All Sections Midterm Examination

(c) ((!(a && b)) == (!a!b)) TRUE / FALSE. (f) ((!(a b)) == (!a &&!b)) TRUE / FALSE. (g) (!(!a) && (c-d > 0) && (b!b))

Intro to Programming in Java Practice Midterm

SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177. Programming

Accelerating Information Technology Innovation

Spring 2013 COMP Midterm Exam Solutions March 07, 2013

Practice Midterm 1 Answer Key

Unit 3. Operators. School of Science and Technology INTRODUCTION

Lecture 3 Operators MIT AITI

CS : Introduction to Computer Programming Final Exam December 9, Please wait to open this exam booklet until you are told to do so.

CS 106 Introduction to Computer Science I

What we will do today Explain and look at examples of. Programs that examine data. Data types. Topic 4. variables. expressions. assignment statements

Building Java Programs

CIS 110 Introduction to Computer Programming Summer 2016 Midterm. Recitation # (e.g., 201):

Final Exam. COMP Summer I June 26, points

Faculty of Science COMP-202A - Foundations of Computing (Fall 2013) - All Sections Midterm Examination

CSCE 145 Exam 1 Review. This exam totals to 100 points. Follow the instructions. Good luck!

Problem Grade Total

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

SAMPLE QUESTIONS FOR DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 1

CSCI 212 Practice Final Exam Summer Instructor: Krishna Mahavadi

AYBUKE BUYUKCAYLI KORAY OZUYAR MUSTAFA SOYLU. Week 21/02/ /02/2007 Lecture Notes: ASCII

Lecture Set 2: Starting Java

Introduction to Java & Fundamental Data Types

Lecture 2: Variables and Operators. AITI Nigeria Summer 2012 University of Lagos.

Numerical Computing in C and C++ Jamie Griffin. Semester A 2017 Lecture 2

Building Java Programs

AP COMPUTER SCIENCE A DIAGNOSTIC EXAM. Multiple Choice Section Time - 1 hour and 15 minutes Number of questions - 40 Percent of total grade - 50

CS 112 Midterm Exam Fall 2016

CSCI 131, Midterm Exam 1 Review Questions This sheet is intended to help you prepare for the first exam in this course. The following topics have

Chapter 3: Program Statements

CS 307 Midterm 2 Spring 2008

CS 177 Spring 2010 Exam I

AP Computer Science Summer Work Mrs. Kaelin

AP COMPUTER SCIENCE A

Transcription:

CS 102 - Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 2010 What is your name?: There are two sections: I. True/False..................... 60 points; ( 30 questions, 2 points each) II. Multiple Choice............... 40 points; ( 8 questions, 5 points each) --------------- 100 points total This test is worth 10% of your final grade. Please fill in your answers on the bubble form. After the test you may keep these pages, but you must turn in your bubble form. This test is open book and open notes. You have 50 minutes. For the multiple choice problems, select the best answer for each one and select the appropriate letter on your answer sheet. Be careful - more than one answer may seem to be correct. Many questions are tricky. Some problems ask you to determine whether something is valid. Something is valid if it would not generate a compiler error and would execute without the program crashing. I. True/False: (2 points each) 1. A Java program can only be run from within BlueJ. 2. Variable names in Java must have at least one upper-case letter. 3. Variable names in Java are limited to a length of 128 characters. 4. Java programs should have a main() method as a starting point. 5. Portions of a line of code in Java that go past the 80th column are ignored. 6. To end a Java program both the break or the exit statement may be used. 7. A do loop (also called a do-while loop) is the best choice for displaying a menu and handling the user response. 8. Consider code used to sum all the numbers between 1 and 1000. Using a for loop will likely mean you will have fewer lines of code as compared to the same code implemented using a while loop. 9. When checking for a logical condition (e.g. whether or not all the pieces are off the board for a player) a while loop is the best choice. 10. Any Java program that can be written using the Eclipse development environment can also be written using the BlueJ development environment. 11. To change your password in your CS account on ernie.cs.uic.edu, you should use the password command. 12. Indentation does not change the meaning of your code in Java. CS 102 - Intro. to Programming, Midterm Exam #1, page 1 of 8

13. The section of code shown below would compile and run and give as output: 3 int sum = 0; for( int i=0; i<3; i++) sum += i; System.out.println( sum); 14. The section of code shown below would compile and run: int sum = 0; for( ;sum>0; ) ; System.out.println( sum); 15. The section of code shown below would compile and run and give as output: Is three Done int x = 3; if( x = 3); System.out.print("Is three "); System.out.println("Done"); 16. Any code that can be written with multiple if-else statements could also be written with a switch-case statement. 17. Any code that can be written with a switch-case statement could also be written with multiple if-else statements. 18. An if-else statement could be rewritten using two if statements without an else. 19. Postfix ++ has precedence over Prefix ++. 20. The following statements are valid (compile and run) in Java: int x = 0; x+= 1; 21. The following statements are valid (compile and run) in Java: int x = 3; int y = 5; x += x+++y++; 22. Parenthesis are not necessary in an if statement in Java, but simply help us separate sections of code. 23. The following statements give a run-time error in Java: String name = "123"; if( name.length() == 3) System.out.println(name.charAt( 3)); CS 102 - Intro. to Programming, Midterm Exam #1, page 2 of 8

24. To check and see if the value of variable x is between 3 and 9 we could use:. int x = 4; if( 3 < x < 9) System.out.println("x is between 3 and 9"); 25. The output of the statement below is: 2 System.out.println( 7 % -3); 26. The output of the statement below is: They are equal Done String name = "Hamlet"; if( name = "Hamlet") System.out.println("They are equal"); System.out.println("Done") 27. After running the code shown below, the value stored in variable y is: 10 int x = 2; int y = 4; y = x++ * ++y; 28. The output of the following lines of code is: Not Done End boolean Done = true; if (Done = false) System.out.println("Not"); if( Done = true) System.out.println("Done "); else System.out.println("Undecided "); System.out.println("End"); 29. The output of the following statements is: 3 Done int x = 2; int y = 1; System.out.print( "" + x + y); System.out.println(" Done"); 30. The following code prints the words: 1 Done char c= a ; switch (c) case a : System.out.print("1"); case b : System.out.print("2"); case c : System.out.print("3"); System.out.println(" Done"); CS 102 - Intro. to Programming, Midterm Exam #1, page 3 of 8

II. Multiple Choice (4 points each) 31. The output of the following code in Java is equal to: a) 2 * 5 b) 2 + 5 c) 25 d) 32 int value = 2; int limit = 5; int result = 1; for(int x=0; x<limit; x++) result = result * value; System.out.println( result); 32. Consider the program segment given below. (Remember that the % operator is the modulus operator, which gives the remainder after integer division.) Its output is: int i=1; while (i<=30) i++; System.out.print(i); if( i%2 == 0) System.out.println(); i++; a) All the numbers from 1 to 30, with a line break after the number 10 b) Even numbers from 1 to 30 all one one line. c) Odd numbers from 1 to 30, each on its own line d) Even numbers from 1 to 30, each on its own line CS 102 - Intro. to Programming, Midterm Exam #1, page 4 of 8

33. Assume an instance of class Confuse is created, and that instance is used to call method doit(). What is the output? class Confuse int x; public Confuse() x = 3; void first( int x, int y) int temp = x; x = y; y = temp; //end method first void second( int a, int b) first( b, a); x = a + 1; //end method second a) Answer is: 2 b) Answer is: 3 c) Answer is: 4 d) Answer is: 7 public void doit() int x = 1; int y = 3; first( x,y); second( y,x); System.out.println("Answer is: " + this.x); //end method doit() //end class Confuse CS 102 - Intro. to Programming, Midterm Exam #1, page 5 of 8

34. Consider the code shown at right below, that uses the Square class demonstrated during class. Note that the display Canvas starts with position (0,0) in the upper-left corner. Adding to the x (horizontal) value moves to the right, and adding to the y value (vertical) moves down. What does the output of this code look like? a) A square that grows larger as it moves to the right. b) A square that moves in a clockwise circle. c) A square that moves in a counterclockwise circle. d) A square that moves in an outward growing clockwise spiral.. public class picture public static void main() Circle firstcircle = new Circle(); firstcircle.makevisible(); for (int i=1;i<31;i++) firstcircle.slowmovevertical((i)*2); firstcircle.slowmovehorizontal((-i)*2); firstcircle.slowmovevertical(-i*2); firstcircle.slowmovehorizontal(i*2); //end for( int i... //end main... //end class picture 35. Consider method second shown at right, which itself uses method first. For positive numbers, how would you best describe its return value? a) x + y b) x * x c) x * y d) x y public int first(int x, int y) int z=0; for (int i=0; i<y; i++) z += x; return z; public int second(int x, int y) int z=1; for (int i=0; i<y; i++) z = first( z, x); return z; CS 102 - Intro. to Programming, Midterm Exam #1, page 6 of 8

36. What does the method shown below do? (Warning, this is a bit involved, so perhaps leave it to the end.) public String method36( String theword) char c; String newword = ""; for( int i=0; i<theword.length(); i++) c = theword.charat( i); newword = ""; for( int j=0; j<theword.length(); j++) if( (j<=i)) newword = newword + theword.charat( j); else if( theword.charat( j)!= c) newword = newword + theword.charat( j); theword = newword; return newword; //end method36() a) Erase the String b) Remove every other letter, starting with the first c) Remove every other letter, starting with the second d) Eliminate all duplicate letters 37. What would be the output of the method call: method37( 14679)); void method37( int number) int x = number; int count = 0; while ( x > 0) x = x / 10; count++; for( int i=0; i<count/2; i++) number = number / 10; System.out.println( number%10); a) 9 b) 1 c) 6 d) Compiler error CS 102 - Intro. to Programming, Midterm Exam #1, page 7 of 8

38. Consider the class given below, along with the driver class for it. class ClassA private int x; public ClassA() x = 1; public void addvalue(int val) x = x + val; //end ClassA class ClassADriver public void doit() int value = 7; ClassA instance1 = new ClassA(); instance1.addvalue( 5); System.out.println("value is: " + instance1.x); //end ClassADriver When running method doit() in the ClassADriver class, the output will be: a) value is: 5 b) value is: 6 c) value is: 7 d) doesn t compile CS 102 - Intro. to Programming, Midterm Exam #1, page 8 of 8