Output Questions for Class 10 ICSE Computer Applications
Predict the output and the number of times the loop runs:
class Test {
public static void main(String args[]) {
int i;
for(i=0;i<5;i++)
System.out.println(i-i*i);
}
}
Java
Java Conditional Stmts
51 Likes
Answer
0 0 -2 -6 -12
Loop executes 5 times
Working
i | Output |
---|---|
0 | 0 |
1 | 1 - 1 * 1 = 0 |
2 | 2 - 2 * 2 = -2 |
3 | 3 - 3 * 3 = -6 |
4 | 4 - 4 * 4 = -12 |
Answered By
28 Likes