Java else if is a like doing another if condition for a true or false value.
Syntax:
if(condition)
{
//execute your code
}
else if(condition n)
{
//execute your code
}
else
{
//execute your code
}
Example:
public class Sample {
public static void main(String args[]) {
int a = 30, b = 30;
if (b > a) {
System.out.println("b is greater");
}
else if(a > b){
System.out.println("a is greater");
}
else {
System.out.println("Both are equal");
}
}
}
Program Output:
No comments:
Post a Comment