File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Code Won Watch "Code Won New topic

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

Kenneth Kim

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

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

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

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 ]
I agree. Here's the link:
subject: Code Won't Compile...If/Else Problems?
It's not a secret anymore!