1)   A byte is
       a)   a single digit of a binary number.
       b)   eight 0s or 1s.
       c)   a character stored in memory.
       d)   a named memory location.

2)   Which of the following is not a primitive data type in Java?
       a)   int
       b)   String
       c)   double
       d)   boolean

3)   Which data type should be used to store a whole number?
       a)   Integer
       b)   String
       c)   int
       d)   double

4)   Which of the following statements initializes a variable?
       a)   int foo;
       b)   int foo = 0;
       c)   foo = 0;
       d)   foo = foo + 1;

5)   Which statement changes the value of the variable named number?
       a)   div = number / div;
       b)   number = number / div;
       c)   System.out.print( number / div );
       d)   int number;

int num1, num2;
num1 = 25;
num2 = 10;
6)   What do each of these expressions evaluate to?
       a)   num1 / num2
       b)   (double) num1 / num2
       c)   num1 % num2
       d)   num1 % num2 / num2

7)   Which statement updates a variable?
       a)   foo = foo + value;
       b)   foo = foo;
       c)   value = foo;
       d)   value = foo + 1;

8)   Which statement correctly updates a counter?
       a)   foo = foo + 1;
       b)   value = foo + foo;
       c)   foo = value + 1;
       d)   value = foo;

9)   Every Java Application contains at least one
       a)   class.
       b)   main method.
       c)   block.
       d)   class, main method, and block.

10)   A Boolean expression
       a)   is used when declaring a variable.
       b)   evaluates to either true or false.
       c)   changes the value of a variable.
       d)   is a type of subroutine that returns a numerical value.

11)   The else portion of an if statement
       a)   is executed when the if condition is false.
       b)   can contain only a single statement.
       c)   must contain multiple statements.
       d)   is executed when the if condition is true.

12)   What message will be displayed when the following code is executed?
int number;
number = 3;
if (number % 2 != 0)
    System.out.print("Odd");
else
    System.out.print("Even");
       a)   Odd
       b)   Even
       c)   OddEven
       d)   There will be no message displayed.

int numItems;
int curCost;
numItems = 6;
curCost = 20;

___13.   Which expression evaluates to true?
             a)   numItems == 6 && curCost > 20
             b)   curCost+21 != curCost+3*7
             c)   !( numItems == 6  )
             d)   numItems == 10 || curCost <= 20

14)   What message is displayed when the following code is executed?
int grade;
grade = 88;
if (grade >= 70)
    System.out.print("C");
else if (grade >= 80)
    System.out.print("B");
else
    System.out.print("A");
       a)   C
       b)   B
       c)   A
       d)   Nothing because none of the assignment statements are executed.

15)   Which statement is used to terminate an application?
       a)   break;
       b)   continue;
       c)   System.exit(0);
       d)   System.out.println();

___16.   What is printed after the following code executes?
for (int i=0; i<5; i++)
    System.out.print("$");

             a)   $
             b)   5
             c)   $$$$$
             d)   $$

17)   Count the number of statements in the following code:
for (int i = 1; i <= num; i++){
    for (int j = 0; j < i; j++)
       System.out.print("*");
    System.out.println();
}

18)   Count the number of blocks in the following code:
public class Prime {
    public static void main(String[] args) {
        int number;
        boolean prime = true;

        System.out.print("What is your number? ");
        number = Stdin.readInt();

        for (int i = 2; i <= number/2; i++)
            if (number % i == 0){
                prime = false;
                break;
            }

        if (prime)
            System.out.println("Prime");
        else
            System.out.println("Not Prime");

        System.exit(0);
    }
}

19)   What is printed when the following code executes?
int number = 57381;
int count = 0;
for ( ; number > 0 ; number /= 10){
    if (number % 10 == 8)
       continue;
    if (number % 10 > 5)
       break;
    count++;}
System.out.println(count);

20)   Find two mistakes in the following code:
int model;
System.out.print("What's the model number (0 to exit)? ");
model = Stdin.readInt();
if (model > 0){
    while (model >= 189 || model <= 195)
       System.out.print("Car is defective.");
    else
       System.out.print("Your car is OK.");
    System.out.print("What's the model number (0 to exit)? ");
    model = Stdin.readInt();
}

___21.   What is printed after the following code executes?
int space = 1;
System.out.print("Good " + space + " Bye");

             a)   GoodBye
             b)   Good Bye
             c)   Good 1 Bye
             d)   Good space Bye

String str = "hi";
double number = 13;
22)   What is wrong with the following statements?
       a)   str = str * 3;
       b)   number = number % 10;

int number, count, sum = 0;
System.out.print("How many grades do you want to enter? ");
count = Stdin.readInt();
for (double i = 0; i < count; i++) {
    System.out.print("Enter grade " + (i+1) + ", to the nearest tenths place: ");
    number = Stdin.readInt();
    sum += number;
}
System.out.println("The average of the grades is " + sum / count);
System.exit(0);
23)   Which variable is the only one with the correct data type?
       a)   count
       b)   number
       c)   sum
       d)   i

24)   Assuming the indentation is correct, find 6 errors in the following code:
public class Foo {
    public static void main(String args[]) {
        int number, number2, sum = 0;
        System.out.print("What's the first number? ");
        number = Stdin.readInt()
        System.out.print(What's the second number? );
        number2 = Stdin.readInt();
        for (int i = number; i < number2; i++);
            sum += number;
            if (number == 50)
               break;
        System.out.print(sum);}
        System.exit(0);
    }

25)   The Stdin.readInt method
       a)   reads text input from the user.
       b)   converts a sequence of
chars to an int.
       c)   returns an
int.
       d)   All of the above are correct.

26)  Match the situation with the appropriate type of control statement:
       a)   while
       b)   do-while
       c)   for

27)   The Console view
       a)   displays the output of the System.out.print method.
       b)   is not useful for debugging an application.
       c)   is only displayed when you are writing the program.
       d)   is use only to declare variables.

28)   How many lines of output are produced by the following code, and how many are blank?
System.out.print("Programming\n");
System.out.println("\n\tis");
System.out.println();
System.out.print("lots of fun.");

29)   A comment is a line of code that
       a)   puts text into the Console window.
       b)   is delimited by a special sequence of characters and doesn't execute.
       c)   causes the program to stop running.
       d)   the user of the program sees.

30)   Which of the following represent correctly formed comments?
        a)    / comment /
        b)    / comment \
        c)    // comment
        d)   \\ comment
        e)    */ comment */
        f)    */ comment /*
        g)    /* comment \*
        h)   \* comment *\
        i)    /* comment */

31)  Match the situation with the appropriate type of control statement:
       a)   nested if
       b)   else-if ladder
       c)   if
       d)   if-else

int hours;
double salary, total;

System.out.print("How many hours did you work? ");
hours = Stdin.readInt();
System.out.print("What is your hourly salary? ");
salary = Stdin.readDouble();

if (hours < 0 || salary < 0)
    System.out.println("Invalid entry"); // A
else {
    if (hours > 40) {
        total = 40 * salary; // B
        total = total + (hours - 40) * (salary * 1.5);
    }
    else
        total = hours * salary; // C

    total = total - (0.3 * total); // D
    System.out.println("You earned " + total);
}
System.exit(0);
32)   Four lines of code are marked A, B, C, and D with comments.  Which are executed when
       a)   -1 and 12.50 are entered?
       b)   37 and -12.50 are entered?
       c)   50 and 10.00 are entered?
       d)   37 and 10.00 are entered?

33)   A computer can
       a)   understand emotions.
       b)   think like a person.
       c)   make decisions.
       d)   make moral judgements.

34)   A compiler
       a)   translates program code into a seperate executable file.
       b)   automatically executes each line of a program as it is read.
       c)   converts Java code to C++ code.
       d)   is not used with Java.

35)   A variable identifier (name)
       a)   must begin with a period.
       b)   must be a Java keyword.
       c)   should not be descriptively named.
       d)   must begin with a letter.

3 - variable
4 - syntax/logic error
5 - division
6 - java history **
7 - break/continue
8 - shortcut operators
9 - for loop
10 - do-while loop
11 - switch/case **
12 - print/println
13 - escape sequences
14 - comments
15 - boolean expressions/variables
16 - order of operations
17 - if, else-if
18 - infinite loop
19 - keeping track of variable contents
20 - casting
21 - assignment statements
22 - data types
23 - compile process **
24 - subroutine that starts the program