About Question enthuware.ocajp.i.v8.2.1299 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Rinkesh
Posts: 35
Joined: Sat Nov 25, 2017 4:13 pm
Contact:

About Question enthuware.ocajp.i.v8.2.1299 :

Post by Rinkesh »

What will the following program print?

Code: Select all

class Test{
   public static void main(String args[]){
      int var = 20, i=0;
      do{
         while(true){
         if( i++ > var) break;
         }
      }while(i<var--);
      System.out.println(var);
   }
}
In do-while loop,The statement is executed first and then the condition is checked.So,shouldn't it check the outer while's condition every iteration and decrement the value of var by 1.Tell me what I am missing.
Last edited by admin on Tue Dec 12, 2017 10:26 pm, edited 1 time in total.
Reason: Please put code inside [code] [/code]

admin
Site Admin
Posts: 10045
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1299 :

Post by admin »

Not sure which statement are you talking about. Do you mean the do block? If so, yes.
It does check the condition i<var-- for every iteration of the do-while block.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 29 guests