Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 172

Given:

What is the result?

    Correct Answer: A

    This Java code snippet contains a for loop that has no body due to the semicolon at the end of the for statement. The loop itself will execute, initializing x to 0 and incrementing it while x is less than 3. On each iteration, the expression sum += ++x will be executed. It increments x before adding it to sum. The sequence of operations will be as follows: when x is 1, sum becomes 1; when x is 2, sum becomes 3; when x is 3, sum becomes 6. After the loop terminates because x is no longer less than 3, the single System.out.print statement outside the loop will execute, outputting the final value of sum prefixed with a dash. Therefore, the output is -6.

Discussion
belal97Option: A

for end in line 1 no body ( ; ) print statmint execute just one time

d7bb0b2Option: A

Is a tricky anwer, so ; only avance the for and set sum to 6 when finish print that number

d7bb0b2Option: A

A=> for has ; no execute sout

Ashan_OzlovOption: A

TESTED

[Removed]Option: A

Confirmed A

StavokOption: A

A is correct TESTED

KiraguJohnOption: A

Its A Sorry I noticed for loop does not have a body and it ends with a semi-colon.

KiraguJohnOption: D

D Tested