wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Code Won't Compile...If/Else Problems? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Code Won Watch "Code Won New topic
Author

Code Won't Compile...If/Else Problems?

Kenneth Kim
Greenhorn

Joined: Aug 11, 2005
Posts: 10
My code won't compile...it always says that I have an else without an if...take a look!

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

You've got lots of extra semicolons like the one below which are causing the error:

else if (something);

There should be no semicolon after those parentheses


[Jess in Action][AskingGoodQuestions]
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Try taking out the semi-colons at the end of each else-if statement, for starters.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Kenneth Albertson
Ranch Hand

Joined: Sep 18, 2005
Posts: 59
Kim, as a good general rule, you will find both syntax and logic errors easier to find if you try to keep your code as simple as possible.

For example, you only need to test fstatus.equalsIgnoreCase("single") once.

Then, once you know that (tincome <= 7300) has failed, there is no need to test for (tincome > 7300), and so on.

Use these guides to restructure your if statements. You will find the resulting logic much simpler, easier to understand, and easier to debug.

It will also be more efficient, but that is off less importance.
[ September 26, 2005: Message edited by: Kym Thompson ]
 
 
subject: Code Won't Compile...If/Else Problems?