KnowledgeBoat Logo

Output Questions for Class 10 ICSE Computer Applications

Predict the Output of the given snippet, when executed:

int x=1,y=1;
if(n>0) 
{
x=x+1; 
y=y+1;
}

What will be the value of x and y, if n assumes a value (i) 1 (ii) 0?

Java

Java Conditional Stmts

ICSE

82 Likes

Answer

(i) n = 1

x = 2
y = 2

(ii) n = 0

x = 1
y = 1

Working

When n = 1, if condition is true, its code block is executed adding 1 to both x and y. When n = 0, if condition is false so x and y retain their original values.

Answered By

37 Likes