About Question enthuware.ocajp.i.v7.2.1042 :
Moderator: admin
-
- Posts: 6
- Joined: Wed Apr 17, 2013 6:35 am
- Contact:
About Question enthuware.ocajp.i.v7.2.1042 :
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
Richie
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
Richie
-
- Site Admin
- Posts: 10102
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1042 :
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 6
- Joined: Wed Apr 17, 2013 6:35 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1042 :
Thank you Paul, good to know
Richie
Richie
-
- Posts: 1
- Joined: Thu Jan 18, 2018 1:07 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1042 :
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.
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.
-
- Site Admin
- Posts: 10102
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1042 :
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.
-
- Posts: 10
- Joined: Wed Mar 03, 2021 5:39 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1042 :
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 this the point where all goes haywire and doesn't compile regardless of the code inside the method?
-
- Site Admin
- Posts: 10102
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1042 :
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.
-
- Posts: 10
- Joined: Wed Mar 03, 2021 5:39 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1042 :
I've attached a print-screen:
- Attachments
-
- this is the question I see on my EnthuWare exam
- Screenshot from 2021-04-09 09-50-29.png (61.5 KiB) Viewed 1938 times
-
- Site Admin
- Posts: 10102
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1042 :
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!
Fixed now.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 37 guests