About Question enthuware.ocajp.i.v7.2.1042 :

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

Moderator: admin

Post Reply
smearaDubha
Posts: 6
Joined: Wed Apr 17, 2013 6:35 am
Contact:

About Question enthuware.ocajp.i.v7.2.1042 :

Post by smearaDubha »

Hi

I have a question in relation to this line :

int j = (i*30 - 2)/100;

I don't understand how this is allowed by the compiler. i is 7 so I thought it would be :

(7*30 - 2)/100 = 2.08

However the compiler makes it equal to 2.

How can this be?

Great questions and forum by the way :D

Richie

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

Re: About Question enthuware.ocajp.i.v7.2.1042 :

Post by admin »

When both the operands of the division operator are int, it performs an integer division i.e. it just truncates the decimal part. In this case, i*30 - 2 is an int and so is 100. So (i*30 - 2)/100 will result in 2.

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

smearaDubha
Posts: 6
Joined: Wed Apr 17, 2013 6:35 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1042 :

Post by smearaDubha »

Thank you Paul, good to know

Richie

geozak
Posts: 1
Joined: Thu Jan 18, 2018 1:07 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1042 :

Post by geozak »

Shouldn't the explanation be:
Remember that a labeled break or continue statement must always exist inside the block where the label is declared. Here, if(j == 4) break POINT1; is a labelled break that is occurring in the second loop while the label POINT1 is declared for the first loop.

Instead of:
Remember that a labeled break or continue statement must always exist inside the loop where the label is declared. Here, if(j == 4) break POINT1; is a labelled break that is occurring in the second loop while the label POINT1 is declared for the first loop.

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

Re: About Question enthuware.ocajp.i.v7.2.1042 :

Post by admin »

You can't have a labeled break or continue unless there is a loop so they must be within a loop and not just any kind of block.
If you like our products and services, please help us by posting your review here.

maria_maria
Posts: 10
Joined: Wed Mar 03, 2021 5:39 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1042 :

Post by maria_maria »

Code: Select all

Consider the following method which is called with an argument of 7:

public void method1(int i, double d){
   int j = (i*30 - 2)/100;
   
   POINT1 : for(;j<10; j++){
       var flag  = false;
       while(!flag){
	if(d > 0.5) break POINT1;
       }
   }
  while(j>0){
     System.out.println(j--);
     if(j == 4) break POINT1;
   }
}
What will it print?
Isn't the premise wrongly worded method which is called with an argument of 7 when the method takes two params?
Isn't this the point where all goes haywire and doesn't compile regardless of the code inside the method?

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

Re: About Question enthuware.ocajp.i.v7.2.1042 :

Post by admin »

Yes, but what you have quoted is not the code presented in the question. The code given in the question is :

Code: Select all

public void method1(int i){
   int j = (i*30 - 2)/100;
...
If you like our products and services, please help us by posting your review here.

maria_maria
Posts: 10
Joined: Wed Mar 03, 2021 5:39 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1042 :

Post by maria_maria »

I've attached a print-screen:
Attachments
this is the question I see on my EnthuWare exam
this is the question I see on my EnthuWare exam
Screenshot from 2021-04-09 09-50-29.png (61.5 KiB) Viewed 103 times

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

Re: About Question enthuware.ocajp.i.v7.2.1042 :

Post by admin »

Ok, I found the issue. Since the thread titled mentioned OCA, I checked the OCA 8 questions bank (where the code was correct) while you are using OCP 11 question bank, where it is incorrect. For some reason, this was changed in OCP 11 question bank.
Fixed now.
thank you for your feedback!
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 7 guests