ExamVeda
Login
Home
This question belongs to Java Program Flow Control
Flow Control
?

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);
      }
}

Answer & Solution
Correct Answer: Option C
Let's discuss the solution. Join the discussion
Examveda
Question posted by Examveda
Community

Join the Discussion

3 Comments
Sai Simron
Sai Simron 6 years ago
In first iteration: i=1,j=1,condn:true
2nd iteration :i=2,j=0,cond: false
prints i=2
Mounika Gangarapu
Mounika Gangarapu 7 years ago
when i = 0;
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
Priy Shukla
Priy Shukla 8 years ago
1st iteration: i=1 and j=1
2nd iteration:i=2 and j=0,
condition false,
Prints i=2.