Expressions and Output MCQ Practice

Question 1 of 10

A harbor display program runs the statements below. Which console output is produced? Line breaks shown in the choices are real line breaks. Ignore a final trailing newline.

System.out.print("Fog");
System.out.println("Horn");
System.out.print("Bay");
  1. A. FogHorn Bay
  2. B. Fog Horn Bay
  3. C. Fog Horn Bay
  4. D. FogHornBay

Question 2 of 10

Trace these output statements. What appears on the console? Treat choice line breaks as actual line breaks and ignore a final trailing newline.

System.out.println("Maple");
System.out.print("Ash");
System.out.println("Birch");
  1. A. Maple Ash Birch
  2. B. MapleAshBirch
  3. C. Maple AshBirch
  4. D. Maple Ash Birch

Question 3 of 10

A scoreboard fragment uses an empty println. What text is displayed? Choice line breaks are real. Ignore a final trailing newline.

System.out.print("Score");
System.out.println();
System.out.print(3 + 4);
  1. A. Score7
  2. B. Score 7
  3. C. Score 3 + 4
  4. D. Score 7

Question 4 of 10

Which text does this string literal display? The quotation marks in the choices are ordinary characters.

System.out.print("Status: \"saved\"");
  1. A. The statement does not compile.
  2. B. Status: saved
  3. C. Status: "saved"
  4. D. Status: \"saved\"

Question 5 of 10

A lab path is stored in a string literal. What characters are displayed?

System.out.print("E:\\labs\\data");
  1. A. The statement does not compile.
  2. B. E:labsdata
  3. C. E:/labs/data
  4. D. E:\labs\data

Question 6 of 10

This literal mixes a quote escape and a newline escape. What is displayed? Choice line breaks are real. Ignore a final trailing newline.

System.out.print("tag: \"ok\"\nend");
  1. A. tag: "ok"end
  2. B. tag: "ok" end
  3. C. tag: \"ok\"\nend
  4. D. tag: ok end

Question 7 of 10

What value does Java produce for this expression?

8 + 6 * 3
  1. A. 42
  2. B. 26
  3. C. 17
  4. D. 48

Question 8 of 10

A student evaluates the two expressions in the table, in row order. Which pair of results is correct?

Expression
19 / 4
19 / 4.0
  1. A. 4 and 4.75
  2. B. 4.75 and 4.75
  3. C. 4 and 4
  4. D. 5 and 4.75

Question 9 of 10

What value does Java produce for this expression?

29 % 6 + 29 / 6
  1. A. 9
  2. B. 4
  3. C. 5
  4. D. 14.833333333333334

Question 10 of 10

What happens when this fragment runs?

int packed = 48;
System.out.print(packed / 0);
  1. A. The console displays 0.
  2. B. The console displays Infinity.
  3. C. The program stops with a run-time error.
  4. D. The code fails to compile because 0 is not allowed in an expression.