Tuesday, June 5, 2012

Else-if statement

Else-if statement

Syntax
if (condition)
 {
statements;
}
 else if (condition) 
{
statements;
}
 else
 {
statements;
}

Program:
 import.java.io.*;
class colour
{
    public static void main(string args[])
    { 
      int color=2
         if(color == 1)) 
         {
            System.out.println("The color is blue.");
         }
         else if(color == 2)
        {
            System.out.println("The color is green.");
        }
       else
     { 
      System.out.println("The color is Red.");
     }
    }
}

Sample Output:
The color is green.
Try Yourself:
1)write a program with your concept using elseif statement

No comments:

Post a Comment

Animated Social Gadget - Blogger And Wordpress Tips