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

1.) What will be the output of the program? for (int i = 0; i < 4; i += 2) { Sys

ID: 3545694 • Letter: 1

Question

1.) What will be the output of the program?

for (int i = 0; i < 4; i += 2)

{ System.out.print(i + " "); }

System.out.println(i); /* Line 5 */

A. 0 2 4

B. 0 2 4 5

C. 0 1 2 3 4

D. Compilation fails.


2.)  What will be the output of the program? i

nt x = 3; int y = 1;

if (x = y) /* Line 3 */

{ System.out.println("x =" + x); }

A. x = 1

B. x = 3

C. Compilation fails.

D. The code runs with no output.


3.) What will you do to treat the constant 3.14 as a long double?

A. use 3.14LD

B. use 3.14L

C. use 3.14DL

D. use 3.14LF

Explanation / Answer

a.)


Option D -

Compilation fails.

Explanation:

Compilation fails on the line 5 - System.out.println(i); as the variable i has only been declared within the for loop.

It is not a recognised variable outside the code block of loop.


b.)


Option C

Line 3 uses an assignment as opposed to comparison. Because of this, the if statement receives an integer

value instead of a boolean. And so the compilation fails.



C.)


Given 3.14 is a double constant.

so use 3.14L

Answer: Option B