Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Java Programming Code Examples

Java > Learning Code Examples

If Else Statement

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
If Else Statement package com.ack.learning; 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..." ); } } }