?
What all gets printed when the following program is compiled and run?
What all gets printed when the following program is compiled and run?
public class Test{
public static void main(String args[]){
int i=0, j=2;
do{
i=++i;
j--;
}while(j>0);
System.out.println(i);
}
}
public class Test{
public static void main(String args[]){
int i=0, j=2;
do{
i=++i;
j--;
}while(j>0);
System.out.println(i);
}
}
Join the Discussion
Login to post a comment or share your explanation.
Login2nd iteration :i=2,j=0,cond: false
prints i=2
a[i] = a[(a[i]+3)%a.length] //a.length =5;
a[0] = a[(a[0]+3)%5];
a[0] = a[(0+3)%5] ; // 3
a[0] = a[3] = 1
when i = 1;
a[1]=a[(a[1]+3)%5];
a[1]=a[(2+3)%5];
a[1]=a[0];
a[1]=1;
Therefore a[1] is equal to 1
2nd iteration:i=2 and j=0,
condition false,
Prints i=2.