Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Test 1) Analyze the following program fragment: int x; double d = 1.5; swit

ID: 3819876 • Letter: J

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 = 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*****

Explanation / Answer

1).c Switch control cannot be variable.

2).B.The programm runs fine and displays it is even

3). E.a

4).C. &&,||,&,*,+D

5).D.23456*****

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote