Examples Of JavaSubscribe to Examples Of Java
b1 b2
 
Examples Of Java MenuMenu Right
Java ProgramsJava ExamplesJava Sample Source CodeTutorial on Java
Home » If Else Statement » If Else Ladder Example
 

If Else Ladder Example

 
  1. /**
  2.  * This example is used to show
  3.  * if else execution
  4.  *
  5.  * @author Examples Of Java
  6.  *
  7.  */
  8. public class IfElseLadderExample {
  9.  
  10. public static void main(String args[]) {
  11.  
  12. /**
  13.  * initialise a variable with 1,
  14.  * change the value of i, to test if else program
  15.  */
  16. int i = 1;
  17.  
  18. /**
  19.  * if i value is less than zero then program prints 'Negative number',
  20.  * if i value is equal to zero then program prints 'Zero'.
  21.  */
  22. if (i < 0)
  23. System.out.print("Negative number");
  24.  else if (i == 0)
  25. System.out.print("Zero");
  26.  else if (i == 1)
  27. System.out.print("One");
  28.  else if (i == 2)
  29. System.out.print("Two");
  30.  else
  31. System.out.print("Greater than two");
  32.  }
  33.  }
  34. /**
  35.  * OUTPUT:
  36.  *
  37.  * One
  38.  *
  39.  */
Source Code:Download
 
Related Examples
 
Most Visited Examples
 
Examples Of Java
left-bottom
 
left-header

Tag Cloud

  ArrayList  HashmapArrays    Java String Examples Calendar  Java StringBuffer Examples    Java Date Class    Iterator    StringTokenizer Hashtable  LinkedHashMap  Basic Java Examples  LinkedList    Float Wrapper Class    BufferedOutputStream    FILE IO    If Else Statement    For Loop    Do While Loop    StaticSingleton    While Loop    Java Language Fundamentals    Data types    Sorting    TreeMap    TreeSet    Sorting Algorithms    Java Date Formatting    Collections  FileOutputStream   Log4j

Java Examples

Java Sample Source Code

Tutorial on Java

java training classes

left-bottom
 
Google Examples Of Java
 
Examples Of Java Examples Of Java