int n1=5,n2=10;
for (int x=1;x <=2;x++)
{
System.out.println (++n1);
System.out.println (n2--);
System.out.println(--n2);
System.out.println(n1++);
}
Answers
Answered by
3
Question:-
Write the output of the following code snippet.
Solution:-
Given,
n1=5
n2=10
for(int x=1,x<=2;x++)
{
System.out.println(++n1);
System.out.println(n2--);
System.out.println(--n2);
System.out.println(n1++);
}
After first execution,
++n1 = 6
n2-- = 10
--n2 =8
n1++ = 6
Output:-
6
10
8
6
Now,
n1=7 and n2=8
After second execution,
++n1=8
n2-- = 8
--n2=6
n1++ = 8
Output:-
8
8
6
8
Hence, required output:-
6
10
8
6
8
8
6
8
Similar questions