1)   A variable 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)   A syntax error is a result of
       a)   an error that occurs when a program is run.
       b)   a statement that violates the rules of Java.
       c)   a statement that includes too many variable declarations.
       d)   a value that is out of range.

3)   Which data type should be used to store a decimal 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 = 5;
num2 = 2;
6)   Which of these expressions evaluates to the largest value?
       a)   num1 / num2
       b)   (double) num1 / num2
       c)   num1 % num2
       d)   num1 % num2 / num2

7)   Which of the following statements does not update a variable?
       a)   foo = foo + value;
       b)   value = foo + 1;
       c)   foo++;
       d)   foo += value;

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

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

int numItems;
int curCost;
numItems = 7;
curCost = 24;

___10.   Which expression evaluates to true?
             a)   numItems == 6 && curCost > 20
             b)   curCost+8 == curCost+40/2
             c)   !( numItems == 6  )
             d)   numItems == 10 || curCost <= 20


11)   What message is displayed when the following code is executed?
int grade;
grade = 83;
if (grade >= 87)
    System.out.print("B+");
else if (grade <= 83)
    System.out.print("B-");
else
    System.out.print("B");
       a)   B+
       b)   B-
       c)   B
       d)   Nothing because none of the assignment statements are executed.

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

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


String fmt = "percent";
double rate = 6.8;

13)   Which of the following statements is legal?
       a)   fmt = fmt * 3;
       b)   rate = rate % 10;
       c)   fmt = fmt + rate;
       d)   rate = fmt + rate;

for (int i = number; i < number2; i++);
14)   The above line of code contains all of the following except:
       a)   update statement
       b)   infinite loop
       c)   initialization statement
       d)   empty statement

System.out.print("What is the number (0 to exit)? ");
int i = Stdin.readInt();
while (i > 0) {
    System.out.print(i);
   
System.out.print("What is the number (0 to exit)? ");
}

15)   The above code contains all of the following except:
       a)   priming read
       b)   sentinel
       c)   infinite loop
       d)   empty statement

16)   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.

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);
17)   Four lines of code are marked A, B, C, and D with comments.
        Which are executed when 45 and 15.00 are entered?
       a)   A
       b)   B and D
       c)   B
       d)   B, C, and D

18)   Which statement will evaluate to 3 if number is equal to 57381?
       a)   number / 10 / 10 % 10
       b)   number / 10 / 10
       c)   number / 10 % 10 % 10
       d)   number % 10 % 10 / 10