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

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

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

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 What is your name?: (4 points for writing it on your answer sheet)

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)

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

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.

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

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

Control Structures in Java if-else and switch

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

Practice Midterm 1. Problem Points Score TOTAL 50

CS 177 Week 15 Recitation Slides. Review

CS111: PROGRAMMING LANGUAGE II

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

CS 112 Midterm Exam Fall 2016

Give one example where you might wish to use a three dimensional array

CS 101 Spring 2007 Midterm 2 Name: ID:

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

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

Intro to Programming in Java Practice Midterm

Some Practice Midterm Problems

CSE 142, Summer 2013 Midterm Exam, Friday, July 26, 2013

Nested Loops ***** ***** ***** ***** ***** We know we can print out one line of this square as follows: System.out.

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

Decisions in Java IF Statements

CS 307 Midterm 1 Fall 2007

Introduction to Computer Science Midterm 3 Fall, Points

Practice Midterm 1 Answer Key

CS302: Self Check Quiz 2

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

AP COMPUTER SCIENCE A

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

Control Structures in Java if-else and switch

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

Question: Total Points: Score:

CS 177 Recitation. Week 8 Methods

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

3/12/2018. Structures. Programming in C++ Sequential Branching Repeating. Loops (Repetition)

CIS October 16, 2018

Problem Grade Total

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

Oct Decision Structures cont d

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

Final Exam. COMP Summer I June 26, points

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

CSCI 1226 Sample Midterm Exam

CSE 142, Autumn 2011 Midterm Exam: Friday, November 4, 2011

CS 302: INTRODUCTION TO PROGRAMMING. Lectures 7&8

Lecture 14. 'for' loops and Arrays

Midterm Review Session

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

Bjarne Stroustrup. creator of C++

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Loops. CSE 114, Computer Science 1 Stony Brook University

Lecture 13: Two- Dimensional Arrays

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

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External

CS 101 Fall 2006 Midterm 1 Name: ID:

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

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

Problem Points Score Grader Total 75

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

CS Week 5. Jim Williams, PhD

Java. Programming: Chapter Objectives. Why Is Repetition Needed? Chapter 5: Control Structures II. Program Design Including Data Structures

Programming Constructs Overview. Method Call System.out.print( hello ); Method Parameters

Term 1 Unit 1 Week 1 Worksheet: Output Solution

Week 4, Wednesday (Spring 2015). Dr. Yoder. Sec 051. Page 1 of 5

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

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

STUDENT LESSON A12 Iterations

CS 177 Spring 2010 Exam I

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

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

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

Computer Programming I - Unit 5 Lecture page 1 of 14

Conditionals, Loops, and Style

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

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

CompSci 125 Lecture 11

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

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

Question: Total Points: Score:

For that purpose, java provides control structures that serve to specify what has to be done by our program, when and under which circumstances.

CIS October 19, 2017

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

1. An operation in which an overall value is computed incrementally, often using a loop.

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

Object-Oriented Programming

CSE 114 Computer Science I

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

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

CSCI 201L Written Exam #1 Fall % of course grade

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

Transcription:

CS 102 - Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009 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. The same valid Java program can be run either from within BlueJ or from the command line. 2. A java class name should be the same as the filename in which it is found. For instance the Book class should be stored in Book.java 3. A single line comment using // can be safely nested inside a block style comment that uses /*...*/ 4. Multiple variables can be declared and initialized at one time, such as: int x=1,y=2,z=3; 5. Multiple variables can all be initialized on the same line, such as: x=y=z=0; 6. The output of the statements below is: 3 System.out.println( value / 2); 7. The output of the statements below is: 3 System.out.println( (int)value / 2); 8. The output of the statements below is: 3 System.out.println( (double)1 * value / 2); CS 102 - Intro. to Programming, Midterm Exam #1, page 1 of 7

9. The output of the statements below is: 3 System.out.println( value / 2 * 1.0); 10. The output of the statements below is: 3 double value = 7.0; System.out.println( value / 2); 11. The following statements are valid (compile and run) in Java: int x = 0; x+= 1; 12. The following statements are valid (compile and run) in Java: int x = 3; int y = 5 x += x+++y++; 13. It is possible in Java to write one line of code that generates 2 lines of output. 14. It is possible in Java to write 2 lines of code that generates 1 line of output. 15. Multi-word variable names in Java should have the first letter of each word capitalized, except for the first word. 16. When creating an instance of the Scanner class, any valid identifier can be used. 17. When writing code to select a menu option declared as a char, a do loop is better than a while loop. 18. When writing code to select a menu option declared as a char, a switch-case statement is preferable to multiple if-else-if statements. 19. When writing code that repeats several lines 0 or more times, a do loop is preferable to a while loop. 20. When writing code that repeats several lines 0 or more times, a do loop is preferable to a for loop. 21. A Java program could have all indentation removed and it would still give exactly the same output; 22. The following statements compile and run in Java: String name = "One"; if( name.length() = 3) System.out.println("Are equal"); 23. 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"); CS 102 - Intro. to Programming, Midterm Exam #1, page 2 of 7

24. The output of the statement below is: 2 System.out.println( -7 % -3); 25. After running the code shown below, the value stored in variable x is: 12 int y = 3; int x = y * y++; 26. The output of the following lines of code is: Done End boolean notdone = false; if (notdone = true) System.out.println("not Done "); if( notdone = false) System.out.println("Done "); else System.out.println("Undecided "); System.out.println("End"); 27. The output of the following statements is: 3 Done int x = 2; int y = 1; System.out.print( x + y + ""); 28. The output of the following statements is: 3 Done int x = 2; int y = 1; System.out.print( "" + x + y); 29. The output of the program segment below is: 3 Done String jumbo = "2"; String shrimp = "1"; System.out.println(jumbo + shrimp); 30. The following code prints the words: 12 Done char c= b ; switch (c) case a : System.out.print("1"); case b : System.out.print("2"); break; case c : System.out.print("3"); break; CS 102 - Intro. to Programming, Midterm Exam #1, page 3 of 7

II. Multiple Choice (4 points each) 31. Consider the program segment given below. Its output is: int i=1; while (i<=100) System.out.print(i); if( i%10 == 0) System.out.println(); i++; a) All the numbers from 1 to 100, with a line break after the number 10 b) All the numbers from 1 to 100 in a grid of 10 rows and 10 columns c) All the numbers from 1 to 101, 4 per row d) All the numbers from 1 to 101, with a line break after every 10 numbers 32. The output of the following code in Java is equal to: a) 2 * 5 b) 2 + 5 c) 25 d) 32 33. The output of the following code in Java is: a) 2 * 5 b) 2 + 5 c) 25 d) 32 int answer=2; int limit = 5; for(int x=0; x<limit; x++) answer = answer + 1; System.out.println( answer); int answer=2; int limit = 5; for(int x=0; x<limit; x++) answer = answer * 2; System.out.println( answer); CS 102 - Intro. to Programming, Midterm Exam #1, page 4 of 7

34. Consider the code shown at right below, that uses the Circle class demonstrated during class. What does the output of this code look like? a) A circle that grows larger as it moves to the right. b) A circle that itself moves in a clockwise circle. c) A circle that itself moves in a counter-clockwise circle. d) A circle 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 the method given below. It can best be described as a method that: public boolean method35( int number) if ( (number==1) (number==2) ) return true; for (int i=2; i < number/2; i++) if ( number%i == 0) return false; return true; a) checks to see if a number is even b) checks to see if a number is odd c) checks to see if a number is prime d) does not compile CS 102 - Intro. to Programming, Midterm Exam #1, page 5 of 7

36. Consider the method given below. If its output is: 3 6 9 4 8 12 5 10 15 6 12 18 How was the method called? public void methodb(int r, int k, int n) int i, j; for( j=k; j<=n; j++) for( i=1; i<=r; i++) System.out.print(" System.out.println(); " + i*j); a) methodb(3, 3, 1); b) methodb(4, 1, 3); c) methodb(3, 6, 3); d) methodb(4, 6, 3); 37. Consider the method given below. What would be the output if this were called using the statement: System.out.println( method37( 54321)); int method37( int number) int x = number; int y = 0; while ( x > 0) y = y * 10 + x%10; x = x / 10; return y; a) 5 b) 12345 c) 234 d) 1 CS 102 - Intro. to Programming, Midterm Exam #1, page 6 of 7

38. Consider the method given below. What would be the output if this were called using the statement: method38(); void method38() int x = 13572; while (x > 10) x = x / 10; System.out.print( x); a) 2 b) 27531 c) 1357 d) 1 CS 102 - Intro. to Programming, Midterm Exam #1, page 7 of 7