Specifications

Sun Services
Java™ Programming Language
Module 4, slide 20 of 31
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
Complex if, else Statements
The if-else-if statement syntax:
if (
<boolean_expression>
)
<statement_or_block>
else if (
<boolean_expression>
)
<statement_or_block>
Example:
int count = getCount(); // a method defined in the class
if (count < 0) {
System.out.println("Error: count value is negative.");
} else if (count > getMaxCount()) {
System.out.println("Error: count value is too big.");
} else {
System.out.println("There will be " + count +
" people for lunch today.");
}