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

Similar documents
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)

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

I. True/False: (2 points each)

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

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

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

I. True/False: (2 points each)

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

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

I. True/False: (2 points each)

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

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

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

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

CS111: PROGRAMMING LANGUAGE II

Section 003 Fall CS 170 Exam 1. Name (print): Instructions:

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

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2013

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

Question: Total Points: Score:

Control Structures in Java if-else and switch

AP CS Unit 3: Control Structures Notes

Midterm Exam CS 251, Intermediate Programming March 12, 2014

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

CS 177 Week 15 Recitation Slides. Review

Practice Midterm 1. Problem Points Score TOTAL 50

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: if Single-Selection Statement CSC 209 JAVA I. week 3- Control Statements: Part I

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

Following is the general form of a typical decision making structure found in most of the programming languages:

AP Computer Science A Unit 2. Exercises

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

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

16. Give a detailed algorithm for making a peanut butter and jelly sandwich.

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

Lecture 14. 'for' loops and Arrays

CS 101 Spring 2007 Midterm 2 Name: ID:

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

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

Problem Grade Total

CIS 110 Fall 2016 Introduction to Computer Programming 13 Oct 2016 Midterm Exam Answer Key

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

Introduction to Java & Fundamental Data Types

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

Term 1 Unit 1 Week 1 Worksheet: Output Solution

Decisions in Java IF Statements

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

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2014

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

Programming with Java

Pace University. Fundamental Concepts of CS121 1

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

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

COE 211/COE 212 Computer/Engineering Programming. Welcome to Exam II Thursday December 20, 2012

Practice Midterm 1 Answer Key

Control Structures in Java if-else and switch

CS 211: Methods, Memory, Equality

CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2013

University of Massachusetts Amherst, Electrical and Computer Engineering

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

Exam 1. CSC 121 Spring Lecturer: Howard Rosenthal. March 1, 2017

CSE 114 Midterm 1. Please leave one seat between yourself and each of your neighbors.

Midterm Examination (MTA)

Introduction to Software Development (ISD) Week 3

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

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

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

Selected Questions from by Nageshwara Rao

In Java, data type boolean is used to represent Boolean data. Each boolean constant or variable can contain one of two values: true or false.

Handout 4 Conditionals. Boolean Expressions.

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

L o o p s. for(initializing expression; control expression; step expression) { one or more statements }

CS 302: INTRODUCTION TO PROGRAMMING. Lectures 7&8

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

CS 302 Week 9. Jim Williams

CP122 CS I. Chapter 6a: Iteration I

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18

Introduction to Computer Science Midterm 3 Fall, Points

CS 101 Exam 1 Spring 200 Id Name

CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, Name:

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

Computer Programming I - Unit 5 Lecture page 1 of 14

2.8. Decision Making: Equality and Relational Operators

CP122 CS I. Iteration

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

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

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011

CS 113 PRACTICE FINAL

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

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Intro to Programming in Java Practice Midterm

CS141 Programming Assignment #6

Accelerating Information Technology Innovation

Oct Decision Structures cont d

CS 101 Fall 2006 Midterm 3 Name: ID:

Transcription:

CS 102 - Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2007 What is your name?: (3 points for writing it on your answer sheet) There are two sections: I. True/False..................... 70 points; ( 35 questions, 2 points each) II. Multiple Choice............... 27 points; ( 9 questions, 3 points each) --------------- 97 + 3 points for name = 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. The name of a Java class should match the file name. 2. Java insists that your program have at least one comment line, otherwise you will get an error. 3. Java programs written in BlueJ can t run as-is. They must first be translated into something the machine understands. 4. Any program that can be written using for loops could be rewritten, substituting do-while loops (and possibly a few other lines of code) in place of each for loop. 5. Any program that can be written with if-else statements could be re-written using only if statements without the else parts. 6. Any variable in Java declared as final becomes a Java reserved word. 7. Every if statement must use curly braces as part of the statement, otherwise it will not compile. 8. Every if statement must use parenthesis ( ) in the decision part of the statement, otherwise it will not compile. 9. A sequence of if-else statements to handle menu options should not be indented inside each other. 10. Consider a sequence of if-else statements that handle assigning a letter grade ( A.. F ) based on a numerical score (0..100). These if-else statements should not be indented inside each other. CS 102 - Intro. to Programming, Midterm Exam #1, page 1 of 8

11. The output of the following lines of code is: No String w1 = "Yes"; if (w1=="yes") System.out.println("Yes"); else System.out.println("No"); 12. The output of the following lines of code is: Yes boolean True = false; if (True = true) System.out.println("Yes"); else System.out.println("No"); 13. The output of the program segment below is the text: Two Done int x = 3; if ( x < 3) if ( x <=5 ) System.out.print("One"); else System.out.print("Two"); System.out.println(" Done"); 14. The output of the program segment below is: Absolutely whatever you say String will = "you "; String No = "Absolutely "; String I = "say"; String way = "whatever "; System.out.println(No + way + will + I); 15. The following two statements give the same output: int quantity = 13; System.out.println("Price is: " + quantity + " dollars."); System.out.printf("Price is: %d dollars\n", quantity); 16. Using System.out.printf() is more convenient for formatting floating point numbers than is System.out.println(). 17. The following two statements give the same output: System.out.println("Code number is: 67"); System.out.println("Code number is: " + (int)'c'); 18. The output of the following statement is the value: B char c='a'; System.out.println( 1 + 'A' ); CS 102 - Intro. to Programming, Midterm Exam #1, page 2 of 8

19. The output of the following statement is the value: 7 System.out.println( Integer.parseInt("7") ); 20. The output of the following statements is: a String theword = "program"; System.out.println( theword.charat( 6)); 21. The output of the following statement is: 2.33333 System.out.println( 7 / 3); 22. The output of the following statement is: 3 System.out.println( 2 * 3.5 / 2); 23. The following statement would compile and run: for( int i=0, sum=0; sum<10; sum+=i, i++); 24. Consider the following statements of code using the BlueJ shapes example discussed in class: Square thesquare = new Square(); System.out.println( thesquare); If this code prints out just a number, that means that most likely the tostring() method has not been implemented in the Square class. 25. The output of the following statement is: 7 System.out.println("Length of \"seven\" is: " + "seven".size() ); 26. Inside a loop if a continue statement is followed by a break statement, then they cancel each other out and it is the same as if both of them were not there. 27. Inside a loop if a break statement is encountered, execution resumes at the next line immediately following the loop. 28. The following code is valid (compiles and runs) in Java: for( ; ; ); 29. The output of the following code in Java is the sum of positive even integers less than 20: int x, answer; for(x=1, answer=0; x<20; x++) if( x%2 == 0) answer+=x; System.out.println( answer); 30. The output of the statement below is: -1 System.out.println( -5 % 2); 31. The following would give a compiler error in Java: int x, y; x + y = 3; CS 102 - Intro. to Programming, Midterm Exam #1, page 3 of 8

32. The following code prints out: Result is: 10 int x=2;for(int i=0; i<5; i++) x+=i; System.out.println("Result is: " + x); 33. The following code prints the words: Give me ambiguity or give me something else int value = 7; System.out.print("Give me ambiguity "); if (2 < value < 10) System.out.print("or give me "); else System.out.print("on second thought "); System.out.print(" something else"); 34. The following code prints the words: 321Done int x=3; switch (x) case 3: System.out.print("3"); case 2: System.out.print("2"); case 1: System.out.print("1"); break; System.out.println("Done"); 35. The equals( ) method should be implemented in every class you write that others may use someday. CS 102 - Intro. to Programming, Midterm Exam #1, page 4 of 8

II. Multiple Choice 1. Consider the program segment given below. Its output is: int answer = 0; for (int i=0; i<5; i++) answer = answer + i; System.out.println( answer); a) 0 b) 4 c) 10 d) 20 2. Consider the program segment given below. Its output is: String x = ""; int y = 3; int z = 5; System.out.println(x + y + z + " is the answer"); a) 3 + 5 is the answer b) 8 is the answer c) 35 is the answer d) 3 5 is the answer 3. Consider the code given below. Its output is: int y = 2; int x = 5; int z = x+++y; System.out.println("Value is: " + x + y + z); a) Value is: 527 b) Value is: 628 c) Value is: 538 d) Value is: 639 CS 102 - Intro. to Programming, Midterm Exam #1, page 5 of 8

4. What is the output of the program segment below when an instance of class Check is created and used to call method checkit()? class Check int x = 0; void checkit() if( one() && two() ) x++; System.out.println( x); boolean one() x++; return false; boolean two() x++; return true; //end class Check a) 0 b) 1 c) 2 d) 3 5. Consider the code given below. If its output is: what are the values for variables k, n, and r? a) int k=4, n=3, r=5; b) int k=3, n=5, r=3; c) int k=3, n=4, r=5; d) int k=3, n=5, r=4; 9 12 15 12 16 20 24 15 20 25 30 35 for( int j=k; j<=n; j++) for( int i=r; i<r+j; i++) System.out.printf("%5d",i*j); System.out.println(); CS 102 - Intro. to Programming, Midterm Exam #1, page 6 of 8

6. What is the output of the code given in the two columns below when an instance of class Confuse is created and used to call method startup()? class Confuse int x=2; int y=5; private void first(int y, int x) x += 2; y += 3; private void second(int x, int s) x += 5; y = 4; private void third(int y) setxy( y); x += 2; y += 3; private void setxy( int y) x = y; this.y = x+1; second(y, x); private void display() System.out.println(x + y); public void startup() int x=3, y=2; first(x,y); second(x,y); third( 4); display(); //end class Confuse a) 8 b) 9 c) 10 d) 11 CS 102 - Intro. to Programming, Midterm Exam #1, page 7 of 8

7. Assume the code shown below right is stored in a file named problems.java Assume that if it ran correctly, the output would be: 2 4 6 8 10 eschew surplusage End How many errors can you find that would prevent this code from running correctly if it were invoked in BlueJ by calling method runit()? a) 1, 2, or 3 b) 4 or 5 c) 6 or 7 d) 8 or 9 class Problem int counter = 5; int runit() runonce(); System.out.println("End"); void runonce(int counter) for( int i=0; i<=counter; i++); System.out.println( i*2); System.out.println("eschew "); System.out.println("surplusage"); 8. Consider methoda shown at right. How would you best describe its return value? a) x + y b) x * x c) x * y d) x y 9. Consider methodb shown at right. How would you best describe its return value? a) x + y b) x * x c) x * y d) x y public int methoda(int x, int y) int z=0; for (int i=0; i<y; i++) z = z + x; return z; public int methodb(int x, int y) int z=1; for (int i=0; i<y; i++) z = methoda( z, x); return z; CS 102 - Intro. to Programming, Midterm Exam #1, page 8 of 8