This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "if statement question from JQ+" Watch "if statement question from JQ+" New topic

if statement question from JQ+

Jon Rosenbaum

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.
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
It is sorta covered in the JavaRanch Style Guide.
subject: if statement question from JQ+
Similar Threads
More basic concepts
How does this " if " statement behave
Clarify the output please . . .
It should throw a runtime error..
java.lang.Comparable and classcastexception probs yo - from OCP Exam 2 by K and B