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
95 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
42 Likes
Related Questions
Predict the Output of the given snippet, when executed:
int a=1,b=1,m=10,n=5; if((a==1)&&(b==0)) { System.out.println((m+n)); System.out.println((m—n)); } if((a==1)&&(b==1)) { System.out.println((m*n)); System. out.println((m%n)); }
Predict the Output of the given snippet, when executed:
int b=3,k,r; float a=15.15,c=0; if(k==1) { r=(int)a/b; System.out.println(r); } else { c=a/b; System.out.println(c); }
Predict the Output of the given snippet, when executed:
switch (opn) { case 'a': System.out.println("Platform Independent"); break; case 'b': System.out.println("Object Oriented"); case 'c': System.out.println("Robust and Secure"); break; default: System.out.println("Wrong Input"); }
When (i) opn = 'b' (ii) opn = 'x' (iii) opn = 'a'