permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes if statement question from JQ+ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "if statement question from JQ+" Watch "if statement question from JQ+" New topic
Author

if statement question from JQ+

Jon Rosenbaum
Greenhorn

Joined: Jul 31, 2001
Posts: 4
Following is the code snippet from one of the questions:

The thing I don't understand is how this compiles. I'm confused because there is a semi-colon at the end of the second if, which to me would make the else be its own statement that is not connected to an if. I'm obviously missing something since it does compile, so I was wondering if someone could please clear the cobwebs for me.
Thanks.
Jon
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
The semi-colon is not at the end of the if statement. It is at the end of the println statement. In Java, every statement must end with a semi-colon.
Also, the else should line up with the second if.
------------------
Tom - SCJP --- Co-Moderator of the Programmer Certification Forums


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
wood burning stoves
 
subject: if statement question from JQ+