Given the following code fragment:
if (value >= 0) {
if (value != 0)
System.out.print(“the “);
else
System.out.print(“quick “);
if (value < 10)
System.out.print(“brown “);
if (value > 30)
System.out.print(“fox “);
else if (value < 50)
System.out.print(“jumps “);
else if (value < 10)
System.out.print(“over “);
else
System.out.print(“the “);
if (value > 10)
System.out.print(“lazy “);
} else {
System.out.print(“dog “);
}
System.out.print(“…”);
What is the result if the integer value is 33?
A.
the fox jump lazy …
B.
the fox lazy …
C.
quick fox over lazy …
D.
quick fox the ….
Explanation:
33 is greater than 0.
33 is not equal to 0.
the is printed.
33 is greater than 30
fox is printed
33 is greater then 10 (the two else if are skipped)
lazy is printed
finally … is printed.
“B”
The Answer is B.
This question is hella hard to solve without proper code indentation. Here is the properly formatted code:
public class Test {
public static void main(String[] args) {
int value = 33;
if (value >= 0) {
if (value != 0)
System.out.print(“the “);
else
System.out.print(“quick “);
if (value 30)
System.out.print(“fox “);
else if (value < 50)
System.out.print("jumps ");
else if (value 10)
System.out.print(“lazy “);
} else {
System.out.print(“dog “);
}
System.out.print(“…”);
}
}
Well that didn’t work. 🙂
B