wood burning stoves
The moose likes Beginning Java and the fly likes if/else selection structure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "if/else selection structure" Watch "if/else selection structure" New topic

if/else selection structure

Dave Kairys
Ranch Hand

Joined: Sep 09, 2005
Posts: 33
Hi. I have the following code:
(more above here)
while (x < myMonth.length){
if(myMonth[x].Days == 31) days31.add(myMonth[x].Name);{System.out.println((String)days31.get(x));
} else{
Upon compiling, it gives the following error message:
'else' without 'if'.
I have scoured my textbook for any answers and all I see is that I have followed the syntax the same way. Any suggestions?
Sunil Kumar Gupta
Ranch Hand

Joined: Aug 26, 2005
Posts: 824
It should be......

if(myMonth[x].Days == 31){
}else {
daysLessThan31.add(myMonth[x].Name); System.out.println((String)

see it works

Lack of will power has caused more failure than lack of intelligence or ability.
My Blog | Red5 Resources | Technology Update | Daily Technology Tips
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11925

your problem is the semi-colon on this line:

if(myMonth[x].Days == 31) days31.add(myMonth[x].Name);

what you have here is an empty block for your 'if' condition. then you have the block:

{ System.out.println((String)days31.get(x));}

then you have an else with no if...

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link: http://aspose.com/file-tools
subject: if/else selection structure
It's not a secret anymore!