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

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

Moderator: admin

Post Reply
ETS User

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

Post 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

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

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

Post by admin »

Hello,

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

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

rosmarci
Posts: 2
Joined: Wed Mar 24, 2021 11:34 am
Contact:

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

Post 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

edufin166@yahoo.com
Posts: 24
Joined: Wed Sep 28, 2022 9:41 am
Contact:

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

Post 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.

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

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

Post 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);
    
   }
}
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests