Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is wrong with this else statement?

 
John Dullson
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone explain to me why I keep getting a syntax error on this else statement?




 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
remove the semicolon from line 21 after if statement.
 
Mike Simmons
Ranch Hand
Posts: 3038
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
phantom swordsmen wrote:
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
line number 21->
if (beerNum > 0);


There's a semi-colon after if statement....
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
removing a semicolon after the if statement.....your code is working fine....
 
Sunil Kumar
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So is the problem with line number 9 i.e. remove the semicolon
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 12097
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic