Output Questions for Class 10 ICSE Computer Applications
Predict the Output of the following Java program:
class dkl
{
public static void main(String args[])
{
int i;
for(i = -1;i<10;i++)
{
System.out.println(++i);
}
}
}
Java
Java Iterative Stmts
97 Likes
Answer
0 2 4 6 8 10
Working
This table shows the changes in the value of i as the for loop iterates:
i | Remarks |
---|---|
-1 | Initial value |
0 | 1st Iteration — i is -1, ++i makes it 0 |
2 | 2nd Iteration — i becomes 1, ++i makes it 2 |
4 | 3rd Iteration — i becomes 3, ++i makes it 4 |
6 | 4th Iteration — i becomes 5, ++i makes it 6 |
8 | 5th Iteration — i becomes 7, ++i makes it 8 |
10 | 6th Iteration — i becomes 9, ++i makes it 10 |
11 | Once i becomes 11, condition is false and loop stops iterating. |
Answered By
48 Likes