programming-examples/java/_Basics/If Else Statement.java

47 lines
1021 B
Java
Raw Normal View History

2019-11-15 12:59:38 +01:00
If Else Statement
public class IfElseStatement {
public static void main( String[] args ) {
boolean single = false;
boolean tall = true;
// one way
if( single )
System.out.println( "i am single" );
// recommended
if( single ) {
System.out.println( "i am single" );
}
// one way
if( single )
System.out.println( "i am single" );
else
System.out.println( "i am not single" );
// recommended
if( single ) {
System.out.println( "i am single" );
}
else {
System.out.println( "i am not single" );
System.out.println( "...but sometimes..." );
}
// note that there can be any number of
// if...else if statements
if( single == true ) {
System.out.println( "i am single" );
}
else if( single == false && tall ) {
System.out.println( "tall, non-single man" );
}
else {
System.out.println( "and all the rest..." );
}
}
}