| Author |
What is wrong with this else statement?
|
John Dullson
Greenhorn
Joined: Aug 11, 2010
Posts: 1
|
|
Can someone explain to me why I keep getting a syntax error on this else statement?
|
 |
Pramod P Deore
Ranch Hand
Joined: Jul 15, 2008
Posts: 629
|
|
|
remove the semicolon from line 21 after if statement.
|
Life is easy because we write the source code.....
|
 |
Mike Simmons
Ranch Hand
Joined: Mar 05, 2008
Posts: 2818
|
|
phantom swordsmen wrote:
|
 |
Kaustubh G Sharma
Ranch Hand
Joined: May 13, 2010
Posts: 1160
|
|
line number 21->
if (beerNum > 0);
There's a semi-colon after if statement....
|
No Kaustubh No Fun, Know Kaustubh Know Fun..
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
"phantom swordsmen",
please check your Private Messages for an important administrative matter.
And, for the fourth time There's a semi-colon after if statement.
|
[My Blog]
All roads lead to JavaRanch
|
 |
Shanky Sohar
Ranch Hand
Joined: Mar 17, 2010
Posts: 1047
|
|
|
removing a semicolon after the if statement.....your code is working fine....
|
SCJP6.0,My blog Ranchers from Delhi
|
 |
Sunil Kumar
Ranch Hand
Joined: Apr 24, 2007
Posts: 76
|
|
So is the problem with line number 9 i.e. remove the semicolon
|
Sunil Kumar
http://goodtoknowit.blogspot.com/
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
Sunil Kumar wrote:So is the problem with line number 9 i.e. remove the semicolon
No. That won't cause a compilation error.
But as an advance notice to the OP. When you run your program and it just sits there doing nothing, the problem is the semi colon on line 9
|
Joanne
|
 |
Shanky Sohar
Ranch Hand
Joined: Mar 17, 2010
Posts: 1047
|
|
no error is on line no 21 only..........check the program.......
because else should immediately follow the nearly if statement..otherwise it gives compilation eror......
if you remove line no 22,23,24,25....then your code will also compile fine....
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 10043
|
|
John,
Here's a little tip to help you get better help around here. When you ask a question like "why do I get a compiler error?" it is of unimaginable help for you to provide the exact text of the compiler error. What the compiler outputs will tell you a LOT about what your problem is, but in particular the exact line where the problem is.
In your case, you say there is an issue with your if statement...and then there are TWO if statements. So now, if someone wants to help you, they have to figure out where the error is...and some people won't bother taking the time.
Your job is to make it as easy as possible for someone to help you.
If you would have provided this:
C:\slop>javac ninety_nine_bottle.java
ninety_nine_bottle.java:26: 'else' without 'if'
else
we would know the exact problem is on line 26, that the IF block was closed somehow, and we'd know immediatly to look at the IF on line 21 instead of the IF on line 11.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
 |
|
|
subject: What is wrong with this else statement?
|
|
|