Class Test2
Class Test2
switch statement?
1. String
2. double
3. int
4. char
snippet?
int meal = 5;
int tip = 2;
1. 1
2. 2
3. 3
4. 6
package registration;
System.out.print((john==jon)+" "+
(john.equals(jon)));
}
1. true true
2. true false
3. false true
4. false false
package planning;
int plan = 1;
if(plan==1) {
System.out.print("Plan A");
1. Plan A
2. Plan B
3. Plan C
statements.
3. Unlike a case statement, the default statement does not take a value.
4. A default statement can only be used when at least one case
statement is present.
if(++thatNumber < 4)
thatNumber += 1;
1. 3
2. 4
3. 5
1. exit
2. break
3. goto
4. continue
else statement.
4. Ternary expressions support int and boolean expressions for the left-
most operand.
package voting;
Integer candidateB) {
5: System.out.print(process || value);
6: }
8: new Election().calculateResult(null,203);
9: }
10: }
1. true
2. false
runtime.
package dinosaur;
public class Park {
int pterodactyl = 6;
long triceratops = 3;
if(pterodactyl % 3 >= 1)
triceratops++;
triceratops--;
System.out.print(triceratops);
1. 2
2. 3
3. 4
package restaurant;
System.out.print("Not enough");
} if(flair==37) {
System.out.print("Just right");
} else {
System.out.print("Too many");
1. Not enough
2. Just right
3. Too many
not true?
4. A case value must match the data type of the switch variable, or be
14. Given the following truth table, which operator for the boolean
x = true x = false
1. --
2. ++
3. ||
4. &&
int hops = 0;
int jumps = 0;
jumps = hops++;
if(jumps)
System.out.print("Jump!");
else
System.out.print("Hop!");
1. Jump!
2. Hop!
package jungle;
short lion = 3;
System.out.print(winner);
1. 11
2. 13
3. 25
switch(dayOfWeek) {
default:
System.out.print("Another Weekday");
break;
case saturday:
System.out.print("Weekend!");
1. byte
2. long
3. int
19. Given the following code snippet, what is the value of dinner
after it is executed?
int day = 4;
"Leftovers";
1. Takeout
2. Salad
3. The code does not compile but would compile if parentheses were
added.
package recreation;
1. Too few
2. Too many
1. 56789
2. 11789
3. 11717
divided by another.
1. /, %
2. –, %
3. %, <
4. –, ||
package transporter;
int cat = 3;
1. 9
2. 11
3. 15
package dessert;
int eaten = 0;
switch(flavors) {
default: eaten--;
System.out.print(eaten);
1. 1
2. 2
3. 3
package mode;
public class Transportation {
System.out.print(travel(500));
1. train
2. 10
26. Fill in the blanks: Given two non-null String objects with
1. ==, equals()
2. !=, equals()
3. equals(), ==
4. equals(), =!
myTestVariable.equals(null)?
1. true
2. false
package city;
System.out.print("1");
System.out.print("2");
System.out.print("1");
else
System.out.print("2");
1. None
2. One
3. Two
29. Which statement about the logical operators & and && is true?
1. The & and && operators are interchangeable, always producing the
4. The & operator always evaluates both operands, while the && operator
int x = 10, y = 5;
x = w ? y++ : y--;
w = !z;
2. 10 10
3. 11 5
4. 12 5
package bob;
System.out.print((bob==notBob)+" "+
(bob.equals(notBob)));
}
1. true true
2. true false
3. false true
4. false false
1. 0
2. 12
3. 14
33. Given the following truth table, the boolean variables p and q,
and the expression p ^ q, what are the missing values in the truth
p = true p = false
q = false
following application?
if(data.length>=1
&& (data[0].equals("sound") ||
data[0].equals ("logic"))
&& data.length<2) {
System.out.print(data[0]);
1. Nothing is printed.
2. sound is printed.
4. logic is printed.
1. *, --, /
2. %, -, *
3. /, *, %
4. *, -, /
37. Given the following Venn diagram and the variables, x, y, and z,
of the diagram?
1. x || z
2. y || (y && z)
3. x || y
4. y && x
compile?
package tornado;
________ red = 5;
switch(colorOfRainbow) {
default:
System.out.print("Home");
break;
case red:
System.out.print("Away");
1. long
2. double
3. int
package transporter;
"Turtle wins!");
1. Hare wins!
2. Turtle wins!
System.out.print(getResult(5)+getResult(1)
+getResult(0)+getResult(2)+"");
}
1. 0
2. 1
3. 0000
4. 1000
package yoyo;
roller) {
System.out.println(tester.runTest(false,true));
1. up
2. middle
3. down
1. +, -
2. &&, !
3. |, -
4. ||, !
int characters = 5;
int story = 3;
: 1;
1. 2.0
2. 3.0
3. The code does not compile but would compile if parentheses were
added.
following application?
System.out.print(weather[0]!=null
&& weather[0].equals("sunny")
&& !false
1. Nothing is printed.
3. Go Outside is printed.
1. 2
2. 11
3. 16
48. Given the following truth table, the boolean variables w and z,
w = true w = false
z = true true
z = false false
2. --, -, *
3. ++, /, *
4. *, ++, %
if(toy<2)
else
return game;
System.out.print(play(5,2));
1. Ball
2. Swim