Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.746 / enthuware.ocpjp.v17.2.963:

Posted: Mon Nov 28, 2011 11:48 pm
by ETS User
The answer is correct but actually the explanation given here is wrong. Consider the loops:

Code: Select all

final int INT1=0, INT2=4;
int i=INT1; 
do { System.out.println(i); }while(i++<INT2);

OR

Code: Select all

int i;
for(i=INT1; i++<INT2; System.out.println(i));
In both cases, the loops will print 1,2,3,4

and not 1,2,3 as is given in the explanation

Re: About Question com.enthuware.ets.scjp.v6.2.746 :

Posted: Tue Nov 29, 2011 7:50 am
by admin
Hello,

The given answer and explanation are correct. Did you try running the code exactly as given?

HTH,
Paul.

Re: About Question com.enthuware.ets.scjp.v6.2.746 :

Posted: Thu Sep 09, 2021 7:11 am
by rosmarci
The loor:

int i=INT1; do { System.out.println(i); }while(i++<INT2);

print: 1 2 and not 1 2 3

So I think this one is the right answer

Re: About Question com.enthuware.ets.scjp.v6.2.746 :

Posted: Fri Nov 04, 2022 3:36 pm
by edufin166@yahoo.com
Admin is correct. however, The problem in this questions is the explanation. It is REALLY poor/vague. So, the only chance to see whats is going on is go to the IDE, and check.

Re: About Question com.enthuware.ets.scjp.v6.2.746 :

Posted: Fri Nov 04, 2022 11:49 pm
by admin
Can you please tell what is vague about the explanation so that more help can be provided?
The explanation sets INT1 and INT2 to 2 and 3 respectively and shows the outputs for all the loops given in the question. One is expected to run the loops mentally (in the exam) but while practicing one can actually put the code snippets in a class and run it like this:

Code: Select all

public class TestClass {
   public static void main(String[] args){
      int INT1=1 ; int INT2=3;
     System.out.println("-----loop in probblem statment ----");
      for(var i=INT1; i<INT2; i++){
        System.out.println(i);
      }

      System.out.println("------option 4---");

      int i=INT1; 
      do { System.out.println(i); } while(i++<INT2);
    
   }
}