Given the following Java code:
1
2
3
4
5
boolean flag = number < 12
if (!flag)
System.out.println("walrus");
else
System.out.println("narwhal");
What is printed to the screen if the value of number is 18?
walrus
What is the correct fully parenthesized version of the following Java expression?
1
25 + 3 * 2 < 50 || 88 == 3 - 2 && 21 < 99
((25 + (3 * 2)) < 50 || ((88 == (3 - 2)) && (21 < 99))
Assuming you have the following declaration:
1
Scanner keyboard;
Which the correct way to read a boolean value?
boolean flag = keyboard.nextBoolean();
What output is generated by the following code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int value = 2;
switch(value)
{
case 1:
System.out.println("Kamchatka");
break;
case 2:
System.out.println("Yakutsk");
case 3:
System.out.println("Irkutsk");
break;
default:
System.out.println("Siberia");
}
1 2 Yakutsk Irkutsk
Given the following java code, what is displayed to the screen?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
char letter = 'a';
switch(letter)
{
case 'a':
case 'b':
System.out.println("Alaska");
break;
case 'c':
case 'd':
System.out.println("Northwest Territory");
break;
default:
System.out.println("Greenland");
}
Alaska
Which of the following best describes how a while
loop works?
The loop body is repeated until the controlling boolean expression is false.
If the body of a while loop needs to contains multiple statements, those statements must be surrounded by which of the following symbols?
{ }
What is the difference between a while
loop and a do-while
loop?
A
while
loop evaluates its controlling boolean expression before the body is executed. Ado-while
loop evaluates its controlling boolean expression after the body is executed.
What does the following code display to the screen?
1
2
3
4
5
6
int number = 0;
while (number < 5)
{
System.out.println(number);
number++;
}
1 2 3 4 5 0 1 2 3 4
What does the following code display to the screen?
1
2
3
4
5
6
int number = 10;
do
{
System.out.println(number);
number--;
} while (number < 5);
10