Else-if statement
Syntax
if (condition)
{
statements;
}
statements;
}
else if (condition)
{
statements;
}
statements;
}
else
{
statements;
}
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 blue.");
}
else if(color == 2)
{
System.out.println("The color is green.");
}
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