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