Computer Science, asked by kapilv936, 11 months ago

What is the output of the following code fragment ?
For(int i=1;i<10;i++)
System.out.println(i);

Answers

Answered by mehularora
11

Answer:

1

2

3

4

5

6

7

8

9

Explanation:

The for loop takes i=1 in the first step. It prints the value stored in i, which is 1. Then it adds 1 to i by the statement "i++". Now it checks if i is less than 10. If yes, it does the thing written in for loop, that is print i, otherwise it stops for loop.

Answered by remyanairlm
3

Answer:

The given statement will give the output as:

1 2 3 4 5 6 7 8 9

Explanation:

For loop is a looping statement having syntax as:

for( ; ; )

Before the first semi-colon, the counter variable is initialized, then the testing condition is given and finally the increment/decrement statement.

Given:

for(int i=1; i<10; i++)

System.out.println(i);

The loop runs from 1 to 9 and therefore this statement will give the output as:

1 2 3 4 5 6 7 8 9

Similar questions