KnowledgeBoat Logo

Output Questions for Class 10 ICSE Computer Applications

What will be the output of the following code?

int m=2;
int n=15; 
for(int i=1;i<5;i++)
m++;
--n;
System.out.println("m="+m);
System.out.println("n="+n);

Java

Java Iterative Stmts

ICSE

181 Likes

Answer

m=6
n=14

Working

As there are no curly braces after the for loop so only the statement m++; is inside the loop. Loop executes 4 times so m becomes 6. The next statement --n; is outside the loop so it is executed only once and n becomes 14.

Answered By

81 Likes