Chapter 16 JAVA Flashcards
How many choices are possible when using a single if-else statement?
A. 1
B. 2
C. 3
D. 4
B. 2
What does the following code fragment write to the monitor?
int sum = 14; if ( sum < 20 ) System.out.print("Under "); else { System.out.print("Over "); System.out.println("the limit."); }
A. Under
B. Over
C. Under the limit.
D. Over the limit.
A. Under
What does the following code fragment write to the monitor?
int sum = 14; if ( sum < 20 ) System.out.print("Under "); else { System.out.print("Over "); System.out.println("the limit."); }
A. Under
B. Over
C. Under the limit.
D. Over the limit.
A. Under
What does the following code fragment write to the monitor?
int sum = 7; if ( sum > 20 ) { System.out.print("You win "); } else { System.out.print("You lose "); }
System.out.println(“the prize.”);
A. You win
B. You lose
C. You win the prize.
D. You lose the prize.
D. You lose the prize.
What does the following code fragment write to the monitor?
int sum = 21; if ( sum != 20 ) System.out.print("You win "); else System.out.print("You lose ");
System.out.println(“the prize.”);
(Notice that the program has changed from the previous question!)
A. You win
B. You lose
C. You win the prize.
D. You lose the prize.
C. You win the prize.
Evaluate (to true or false) each of the following expressions:
14 <= 14 14 < 14 -9 > -25 -25 > -9
A. true true true true
B. true false false false
C. true false true true
D. true false true false
D. true false true false
What does the following code fragment write to the monitor?
int roll = 13;
if ( roll > 20 ) System.out.println("Jackpot!"); else { if ( roll < 10 ) System.out.print("You lose "); else System.out.print("You win "); System.out.println("the prize."); }
A. Jackpot!
B. You lose
C. You win
D. You win the prize.
D. You win the prize.
What does the following code fragment write to the monitor?
int temp = 62;
if ( temp > 60 ) { if ( temp > 80 ) System.out.println("Hot"); else System.out.println("Moderate"); } else System.out.print("Chilly");
A. Hot
B. Moderate
C. Chilly
D. Nothing is printed
B. Moderate
What does the following code fragment write to the monitor?
int temp = 32;
if ( temp >= 60 ) { if ( temp >= 80 ) System.out.println("Hot"); else System.out.println("Moderate"); } else { if ( temp >= 40 ) System.out.println("Chilly"); else System.out.println("Frigid"); }
A. Hot
B. Moderate
C. Chilly
D. Frigid
D. Frigid
What does the following code fragment write to the monitor?
int temp = 40; // Note change
if ( temp >= 60 ) { if ( temp >= 80 ) System.out.println("Hot"); else System.out.println("Moderate"); } else { if ( temp >= 40 ) System.out.println("Chilly"); else System.out.println("Frigid"); }
A. Hot
B. Moderate
C. Chilly
D. Frigid
C. Chilly
What does the following code fragment write to the monitor?
int score = 82;
if ( score >= 80 ) { if ( score >= 90 ) System.out.println("A"); else System.out.println("B"); } else { if ( score >= 70 ) System.out.println("C"); else System.out.println("D"); }
A. A
B. B
C. C
D. D
B. B