|
Java Reference Home | Smart Soft Home |
|
|
else
DescriptionTheelse keyword does not stand on it's own. It is an optional adjunct to the if keyword.
The if/else combination basically executes a statement(or statements) if some condition is true.
Otherwise, execute another statement(or statements).
Example 1
if (x<10) {
System.out.println("Small number");
}
else {
System.out.println("Big number");
}
Example 2
if (x == 1) {
System.out.println("Spades");
}
else if(x == 2){
System.out.println("Hearts");
}
else if(x == 3){
System.out.println("Clubs");
}
else if(x == 4){
System.out.println("Diamonds");
}
else{
System.out.println("Invalid Suit");
}
See Alsoif |
|