229k views
5 votes
On What is the output of the following code: int i = 1; while (i <= 9)

{
system. out.print(i+"");
i=i+2;
}​

User Roseni
by
4.2k points

1 Answer

2 votes

Answer:

13579

java

Step-by-step explanation:

notice that the System.out.print call does not output a new line.

so... it is going to print 1, then what is 1 plus 2? the answer is 3.

what is 3 plus 2? the answer is 5.

what is 5 plus 2? the answer is 7.

what is 7 plus 2? the answer is 9.

now if we proceeded, i is more than 9, thus ends the while loop.

the output is 13579

because there are no newlines, the numbers are all squished together on the same line.

User Elyana
by
4.4k points