Output Questions for Class 10 ICSE Computer Applications
The following is a segment of a program.
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 Iterative Stmts
ICSE 2009
64 Likes
Answer
(i) 1
x = 2
y = 2
Working
As n is 1, so if condition is true. x and y are incremented by 1 so both become 2.
(ii) 0
x = 1
y = 1
Working
As n is 1, so if condition is false. Values of both x and y remain unchanged.
Answered By
35 Likes