nerdexam
Oracle

1Z0-803 · Question #179

Given: What is the result?

The correct answer is A. 6 7 8. The program executes a 'for' loop that initializes an integer 'i' to 6, continues as long as 'i' is strictly less than 9, and prints the value of 'i' in each iteration.

Using Loop Constructs

Question

Given:

What is the result?

Exhibit

1Z0-803 question #179 exhibit

Options

  • A6 7 8
  • B7 8 9
  • C0 1 2
  • D6 8 10
  • ECompilation fails

How the community answered

(15 responses)
  • A
    73% (11)
  • B
    7% (1)
  • D
    13% (2)
  • E
    7% (1)

Why each option

The program executes a 'for' loop that initializes an integer 'i' to 6, continues as long as 'i' is strictly less than 9, and prints the value of 'i' in each iteration.

A6 7 8Correct

The 'for' loop starts with 'i = 6', prints '6'. It then increments 'i' to '7', prints '7'. Finally, 'i' becomes '8', prints '8'. When 'i' increments to '9', the condition 'i < 9' is false, and the loop terminates, resulting in the output "6 7 8".

B7 8 9

This choice would require the loop to start printing from '7' and continue to '9', which would imply different loop bounds (e.g., 'for (int i = 7; i < 10; i++)').

C0 1 2

This choice represents numbers far outside the likely range of the loop's starting point (e.g., 'for (int i = 0; i < 3; i++)').

D6 8 10

This choice shows numbers with an increment of 2 (6, 8, 10), which would require a step increment (e.g., 'i += 2') and potentially different loop bounds.

ECompilation fails

The code structure described (a simple 'for' loop printing integers) is syntactically correct and will compile without errors.

Concept tested: for loop iteration and bounds

Source: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html

Topics

#looping#output prediction#array iteration

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice