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

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

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

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

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

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

I. True/False: (2 points each)

I. True/False: (2 points each)

I. True/False: (2 points each)

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 102/107 - Introduction to Programming Midterm Exam #2 - Prof. Reed Spring 2011

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

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

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

Practice Midterm 1. Problem Points Score TOTAL 50

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

Control Structures in Java if-else and switch

Programming with Java

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

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

CS 177 Week 15 Recitation Slides. Review

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

Question: Total Points: Score:

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

AP Computer Science A Unit 2. Exercises

Pace University. Fundamental Concepts of CS121 1

CSE 142/143 Unofficial Style Guide

CSE 142, Autumn 2008 Midterm Exam, Friday, October 31, 2008

Decisions in Java IF Statements

CS111: PROGRAMMING LANGUAGE II

Mr. Monroe s Guide to Mastering Java Syntax

Oct Decision Structures cont d

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

Midterm Examination (MTA)

APCS Semester #1 Final Exam Practice Problems

Exam 1 - (20 points)

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

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

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

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

Final Exam Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 20 May 2010

CS 312 Midterm 1 Spring 2013

Practice Midterm 1 Answer Key

First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010

Chapter 4 Loops. int x = 0; while ( x <= 3 ) { x++; } System.out.println( x );

Accelerating Information Technology Innovation

Midterm Exam CS 251, Intermediate Programming March 12, 2014

Question: Total Points: Score:

Control Structures in Java if-else and switch

CSCI 2101 Java Style Guide

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

class objects instances Fields Constructors Methods static

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

CS 177 Recitation. Week 8 Methods

CS 302: INTRODUCTION TO PROGRAMMING. Lectures 7&8

1. Find the output of following java program. class MainClass { public static void main (String arg[])

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

Object-Oriented Programming

CIS 110 Introduction to Computer Programming. 13 February 2013 Make-Up Midterm Midterm

last time in cs recitations. computer commands. today s topics.

Logic & program control part 2: Simple selection structures

Introduction to Java & Fundamental Data Types

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

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

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

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 8: SEP. 29TH INSTRUCTOR: JIAYIN WANG

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

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

1. [3 pts] What is your section number, the period your discussion meets, and the name of your discussion leader?

AP CS Unit 3: Control Structures Notes

Name Section Number. CS110 Exam #1 *** PLEASE TURN OFF ALL CELLPHONES ***

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

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

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

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each

Use the scantron sheet to enter the answer to questions (pages 1-6)

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

Ticket Machine Project(s)

CSCE 206: Structured Programming in C++

CSC 1300 Exam 4 Comprehensive-ish and Structs

CS 112 Introduction to Programming

Place your name tag here

CIS 110 Introduction to Computer Programming. 7 May 2012 Final Exam

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

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

CS 251 Intermediate Programming Java Basics

Final Exam. COMP Summer I June 26, points

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

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

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 #1 Fundamentals of Computer Science I Fall 2013

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

CS 113 PRACTICE FINAL

CP122 CS I. Iteration

CS 231 Data Structures and Algorithms Fall Event Based Programming Lecture 06 - September 17, Prof. Zadia Codabux

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

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 25, Name: KEY A

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

Transcription:

CS 102 - Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 2008 What is your name?: (4 points for writing it on your answer sheet) There are two sections: I. True/False..................... 66 points; ( 33 questions, 2 points each) II. Multiple Choice............... 30 points; ( 10 questions, 3 points each) --------------- 96 + 4 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. In BlueJ, you don t have to have a main( ) method, even though normally you do in a Java project. 2. If separate lines in a program accidentally get put onto the same line, even though the program will compile properly, it will not run properly. 3. There are three different looping structures in Java, however any program could be rewritten using only one of them. 4. The && boolean operator in Java is useful in combining two different conditions which must both be true before the code inside an if statement is executed. A logically equivalent program could be written without the use of &&, using an extra if statement instead. 5. One way to make a variable into a constant in Java is to use the const keyword. 6. Reserved words in Java can be used as variables if the capitalization of the first letter is changed. 7. Curly braces can be used interchangeably with parenthesis ( ) in Java to mark a block of code. 8. Indentation is only for humans to look at in a Java program. The compiler doesn t care whether or not Java code is indented properly. 9. Code that loops a predetermined number of times is best represented using a counter variable with a while loop. 10. A for loop could be used with a boolean ending condition variable to determine whether or not a program is done. CS 102 - Intro. to Programming, Midterm Exam #1, page 1 of 7

11. A sequence of if-else statements to handle menu options should not be indented inside each other. 12. 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. 13. The output of the following lines of code is: Yes String w1 = "Yes"; if (w1=="yes") System.out.println("Yes"); else System.out.println("No"); 14. The output of the following lines of code is: Yes String w1 = "Yes"; String w2 = new String("Yes"); if (w1==w2) System.out.println("Yes"); else System.out.println("No"); 15. The output of the following lines of code is: Yes boolean False = false; if (False = true) System.out.println("Yes"); else System.out.println("No"); 16. The output of the program segment below is the text: Medium Large int x = 2; if ( x > 5) if ( x < 3 ) System.out.print("Small"); else System.out.print("Medium"); System.out.println(" Large"); 17. The output of the program segment below is: anarchy rules String jumbo = "anarchy "; String shrimp = "rules "; System.out.println("jumbo" + "shrimp"); 18. The easiest way to line up numbers of various sizes in a table is using System.out.printf( ) 19. The output of the following statement is the value: B char B ='A'; System.out.println( B ); CS 102 - Intro. to Programming, Midterm Exam #1, page 2 of 7

20. The output of the following statements is: 1 Done String theword = "12345"; System.out.println( "" + theword.charat( 1) + " Done"); 21. The output of the following statement is: 3.5 System.out.println( 7 / 2); 22. The output of the following statement is: 3 System.out.println( 2 * 3.5 / 2); 23. The output of the following statement is: 10 System.out.println( 2 + 3 * 2); 24. Programs used to use goto statements, but now more commonly use constrained forms of goto by using the continue and break statements. 25. Any code that could be written using a goto statement can be written without a goto statement. 26. Several lines of code that include // style comments, can all be commented out as a chunk of code by using /* */ style comments. 27. The following code is valid (compiles and runs) in Java: for( ; ; ) 28. The output of the following code in Java is: 2500 int x, answer; for(x=1, answer=0; x<100; x++) answer = answer + x; System.out.println( answer); 29. The output of the statement below is: -1 System.out.println( -7 % 3); 30. The following would give a compiler error in Java: int x = 1, y = x + 2; 31. Constructors in a class must all have the same name. 32. Methods in a class must all have different names. 33. The following code prints the words: third Done char c= c ; switch (c) case c : System.out.print("third"); case b : System.out.print("second"); case a : System.out.print("first"); break; System.out.println(" Done"); CS 102 - Intro. to Programming, Midterm Exam #1, page 3 of 7

II. Multiple Choice 1. Consider the program segment given below. Its output is: int answer = 1; for (int i=1; i<3; i++) answer = answer * i; System.out.println( answer); a) 0 b) 2 c) 4 d) 6 2. Consider the program segment given below. Its output is: int x = 2; int y = 3; String z = ""; System.out.println(x + y + z + " is the answer"); a) 2 + 3 is the answer b) 5 is the answer c) 23 is the answer d) 2 3 is the answer 3. Consider the program segment given below. Its output is: String x = ""; int y = 2; int z = 3; System.out.println(x + y + z + " is the answer"); a) 2 + 3 is the answer b) 5 is the answer c) 23 is the answer d) 2 3 is the answer CS 102 - Intro. to Programming, Midterm Exam #1, page 4 of 7

4. Consider the code given below. Its output is: int x = 3; int y = 6; int z = x+++y; System.out.println("Value is: " + x + y + z); a) Value is: 369 b) Value is: 469 c) Value is: 4610 d) Value is: 3710 5. 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; a) 0 b) 1 c) 2 d) 3 void checkit() if( one()) if( two()) System.out.println( x); boolean one() return true; boolean two() return false; //end class Check CS 102 - Intro. to Programming, Midterm Exam #1, page 5 of 7

6. Consider the code given below. If its output is: 9 12 12 16 15 20 18 24 what are the values for variables start, end, first and last? for( int i=start; i<=end; i++) for( int j=first; j<last; j++) System.out.printf("%5d",i*j); System.out.println(); a) int start=3, end=6, first=3, last=4; b) int start=1, end=4, first=9, last=12; c) int start=9, end=4, first=9, last=2; d) int start=2, end=4, first=4, last=2; 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 or 2 b) 3 or 4 c) 5 or 6 d) 7 or 8 class Problem int runit() runonce(); System.out.println("End"); void runonce(int Counter) for( int i=1; i<counter; i++); System.out.print( i*2); System.out.println("eschew "); System.out.println("surplusage"); CS 102 - Intro. to Programming, Midterm Exam #1, page 6 of 7

8. Consider method first 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 method second 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 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; 10. Consider the BlueJ Shapes example discussed in class that allows us to create Squares, Triangles, and Circles. Consider what the code might look like if we wanted to create a tic-tac-toe board that looks like what is shown below, where we need to be able to place an X or an O in each square. Which approach shown below would be the best? a) Define a variable of type Square, then reuse it to create 9 squares. b) Define 9 different Square variables. c) Define 10 Square variables, one used for the outer edge d) Draw a square for the outline, then draw 4 lines inside it CS 102 - Intro. to Programming, Midterm Exam #1, page 7 of 7