Sie sind auf Seite 1von 6

Seat Number Name

CS 1063 Introduction to Computer Programming


Full Practice Midterm Exam 1
Section 1 Spring 2015
This is a closed book exam. Answer all of the questions on the question paper in the space provided. If you need
additional space, you can ask for more paper. This is a 50-minute exam.

1) (10 points, 1 point each) Match each of the terms on the left by choosing the upper case letter of the best
answer on the right and putting it next to the lower case letter in the space provided.

a. algorithm A. a group of java methods with a name

b. binary number B. a single command that can be executed

c. compiler C. a command to execute the statements in a method

d. class D. a base-2 number, composed of 0s and 1s

e. decomposition E. the method that is called to start a Java program

f. flow of control F. the order in which statements are executed

g. identifier G. a step-by-step description to perform a task

h. main method H. a program that checks and translates a program

i. method call I. a name of a part of a program, such as a method

j. statement J. separation of a task into subtasks

2) (10 points, 1 point each) Match each of the notations or keywords on the left by choosing the upper case
letter of the best answer on the right and putting it next to the lower case letter in the space provided.

a. " " A. used to begin a method

b. // B. a method that starts a Java program

c. ; C. increment a variable

d. \n D. used for declaring class constants

e. ++ E. escape sequence for a newline

f. double F. primitive type for real numbers

g. Scanner G. begins a comment

h. public static final H. ends a statement

i. public static void I. used for reading input from the keyboard

j. main J. contains a string


3) (10 points) Convert the first two from binary to decimal and the last from decimal to binary

1010 110101 35

4) (20 points, 2 points each) Find the value of each of the following expressions:

a. 2 + 3 * 5

b. 2 * 5 + 3

c. 2 / 3 + 3 / 2

d. 23 % 6

e. 5 / 3 + 7 / 2.0 - 6 / 5

f. 24 % 3 * 3 - 7.0

g. 3.2 * 2.0 / 4 + 5

h. 6 + (18 % (17 - 12))

i. 4/3 * 3.14 * 2

j. 37 / 17.0 * 17

5) (5 points) What is printed by the following code segment:

int x = 5;
int y = 8;
x = x + y;
System.out.println("The values are "+ x + " and " + y);
y = 9;
Name

6) (5 points) What is printed by the following code segment:

System.out.println("abc");
System.out.print("def");
System.out.println("xyz");

7) (5 points) What is printed by the following code segment:

int j;
for (int i=0; i<=11; i = i + 3) {
j = i - 3;
System.out.println("The value is "+ i + j);
}
8) (5 points) What is printed when the printAll method is called?

public static void printAll() {


print1();
print2();
print3();
print1();
}
public static void print1() {
System.out.print("Hello!");
}
public static void print2() {
print1();
System.out.println("How are you?");
}
public static void print3() {
print2();
print1();
}
Name

9) (10 points) Write a complete program that prints your full name.

10) (10 points) Suppose that CONSOLE has already been declared and initialized by:
public static final Scanner CONSOLE = new Scanner(System.in);
Write a program segment that prompts the user for his age in years, and prints out the value entered with an
appropriate message.
11) (5 points) Write a method that uses a for loop to print the integers from 4 to 15 all on one line, separated by
blanks.
The output should look like: 4 5 6 7 8 9 10 11 12 13 14 15

12) (5 points) Suppose you have already written each of the following three methods printOneBlank(),
printOneStar(), and printOneNewline(), and these each do the obvious thing.
Write a code segment that uses nested for loops to print the following pattern. Your code segment may use
the above methods but may not use System.out.print or System.out.println.
**
* *
* *
* *
* *
* *
Exactly 6 lines should be printed and the first * in the last line is in column 1.
Do not write the methods printOneBlank(), printOneStar(), and printOneNewline().
Hint: In line k, write a formula for:
a) the number of leading blanks
b) the number of blanks between the *’s

Das könnte Ihnen auch gefallen