Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Currently new to java, and right now I'm doing an assignment involving if else statements. Can someone please why javac is reading my else as dangling? My syntax should be right unless I am missing something here.
You have to remove your Semicolon after the if-statement. Otherwise the braces after the if are not executed.
I hope this will fix your Problem.
if(Statement);
{
//The Content would not be executed in realtion to the if-statemen
}
Otherwise:
if(Statement)
{
//The Content would be executed in realtion to the if-statemen
}
remove the semicolon(;) after the if statement
You have a semicolon after your if. Remove it.
You have to remove the ; at the end of the line starting with if.
change :
if(...);
{
////
}
to
if(...)
{
////
}
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I've tried my utmost to reproduce this in another way, but it seems that only this line gives the error (please excuse the comment):
return foo.containsKey(MARKET_DATA) && !foo.get(MARKET_DATA).isMissing();/*mapping code can inject a Missing type*/;
However I type this it gives me an error: "unreachable statement". Why is this?
This is clear if you remove the comment:
return foo.containsKey(MARKET_DATA) && !foo.get(MARKET_DATA).isMissing();;
Note well the two semicolons at the end: empty statements are allowed in Java, but this particular empty statement is unreachable as the previous statement always returns.
(For the avoidance of doubt, a comment should not be terminated with a ;).
The issue is because of the ; after the comment:
/*mapping code can inject a Missing type*/;
The compiler thinks there is another statement after the return statement. If you delete the ; after the comment it will work fine (or put it inside the comment).
As per Java specs ; is a empty statement. So there is a statement after return
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Can you please help me make the following code work?
for(int a=0, b=0; a<101; b<102; a++; b++;) {
stuff
}
You got the initialization (first) part of the loop right.
The termination or condition (second) part of the loop should be evaluated to a boolean, so assuming you require an AND relation between the conditions on a and b, it becomes a<101 && b<102. You might want || (OR) instead, depending on your logic.
The increment (third) part of the loop should contain comma separated expressions (same as the initialization part which you already got right).
I also removed an extra ';' from the end.
for(int a=0, b=0; a<101 && b<102; a++, b++) { stuff }
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
If I have an if statement that includes a string like this:
double GUInumber1 = ((GUInumber1 >= 0 || <= 0)? Double.parseDouble(GUIfirstNumber) : 0);
('GUIfirstNumber' is the string)
Why does it come up as a error? Do I need brackets somewhere, do I need to use 'If/else' instead?
Supposedly my compiler says it does not recognize or (||), is this supposed to be something else or does this work in a completely different way.
Any help on this situation would be appreciated, also, if you need to know or are just wondering why I want to make a if statement for a string its because whenever I try to put in a letter instead of a number Java crashes, I'm hoping I could get this to alternatively solve the situation instead.
EDIT:
Solved, had to remove 'or' statements and alternatively make more else statements instead.
This expression (GUInumber1 >= 0 || <= 0) is not correct.
You will need something on both sides of the <= operator.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I'm trying to count the number of items in a scanner object which are divisible by 2.
My code looks like this:
while (s.hasNext()) {
num = s.nextInt();
if ((num % 2) == 0); {
count++;
}
}
For every integer in the object though, count is increasing by 1, regardless if it is divisible by 2, or not. Can someone tell me what I'm doing wrong?
You have a semicolon (;) after your if clause. That means empty code is executed if the condition is true and the code in the code block is always executed.
The ; after the if should be omitted
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I get the error message "continue cannot be used outside of a loop" but it is inside a loop i think?
public void run() {
// TODO Auto-generated method stub
while (isItOK == true);{
//perform canvas drawing
if (!holder.getSurface().isValid()){
continue;
}
Canvas c = holder.lockCanvas();
c.drawARGB(255, 150, 150, 10);
holder.unlockCanvasAndPost(c);
Here is the cause of your error:
while (isItOK == true);{
remove ; before {
When you put a semicolon after a while loop statement, for example in your code:
while (isItOK == true);
It says to not do anything until that statement is no longer true. Therefore, your code will not commence until isItOK == false.
Simply put, by adding the semicolon you already closed your while loop, so "continue" is considered to be outside of it.
Remove the semicolon and it should work.
EDIT: My apologies, marcin_j, apparently I missed that you had already answered this question.