Professional Documents
Culture Documents
m++ = 3
--n =14
m+= ++m
m=m + ++m
m= 3+4
m=7
Output
i=5
m=7
n=14
Q2. What will be the output of the following code snippet? How many times the
loop gets executed? [Show the dry run]
}
Ans.
a x a%x>0 Output
10 7 3>0 true 3
11 9 2>0 true 2
12 11 1>0 true 1
13 13 0>0 false
Output:-
3
2
1
The loop will execute three times
Q4. What will be the output of the following code snippet? How many times the
loop gets executed?
(a) int x=5, y=500;
do
{
y=y/x;
if(y==20)
continue;
System.out.println(y);
}
while(x<=y);
Ans.
x y y=y/x y==20 continue Output x<=y
5 500 100 100==20 false - 100 5<=100 true
5 100 20 20==20 true - 5<=20 true
5 20 4 4==20 false - 4 5<=4 false
Output:-
100
4
The loop will execute three times
(b) int a=10, x=7;
do
{
System.out.println(“value= ”+(a%x));
if(x==9)
break;
a++;
x+=2;
}
while(a%x>0);
Ans.
a x Output (a%x) x==9 break a++ x=x+2 a%x>0
10 7 3 7==9 false - 11 9 2>0 true
11 9 2 9==9 true - - -
Output:-
3
2
The loop will execute two times