OCA Java SE 8 Mock Exam 2 - OCA Mock Question 9








Question

Which of the following do/while loops will compile without errors?

            a.  int i = 0;  
                do {  
                   System.out.println(i++);  
                } while (i < 50); 

            b.  int i = 0;  
                do  
                   System.out.println(i++);  
                while (i < 50); 

            c.  int i = 0;  
                do   
                   System.out.println(i++);  
                while i < 50; 

            d.  i = 0;  
                do  
                   System.out.println(i);  
                   i++;
                   i++;  
                   i++;  
                while (i < 50); 





Answer



A and B

Note

C needs parentheses around the expression, i < 5.

D requires a block statement if more than one statement is used between the do and while keywords.