Question: Java Test 1) Analyze the following program fragment: int x; double d = 1.5; switch (d) { case 1.0: x = 1; case 1.5: x
Java Test
1) Analyze the following program fragment:
int x; double d = 1.5; switch (d) { case 1.0: x = 1; case 1.5: x = 2; case 2.0: x = 3; }
A) The switch control variable cannot be double. B) The program has a compile error because the required break statement is missing in the switch statement. C) The program has a compile error because the required default case is missing in the switch statement. D) No errors
. 2) Analyze the following code: boolean even = false; if (even = true) { System.out.println("It is even!"); }
A) The program runs fine, but displays nothing. B) The program runs fine and displays It is even!. C) The program has a runtime error. D) The program has a compile error.
3) What is the printout of the following switch statement?
char ch = 'a'; switch (ch) { case 'a': case 'A': System.out.print(ch); break; case 'b': case 'B': System.out.print(ch); break; case 'c': case 'C': System.out.print(ch); break; case 'd': case 'D': System.out.print(ch); }
A) abc B) abcd C) a b D) aa E) a
4) The order of the precedence (from high to low) of the operators +, *, &&, ||, & is: 4) A) * , +, &, &&, || B) * , +, &&, ||, & C) &&, ||, &, *, + D) &, ||, &&, *, + E) * , +, &, ||, &&
5) The statement System.out.printf("%10s", 123456) outputs ________. (Note: * represents a space)
A) ****123456 B) 12345***** C) 123456**** D) 23456*****
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
