We will execute another code block by using else if our condition returns false.
int mark=76;
if ( mark >80) {
System.out.println("More than 80");
}
else {
System.out.println("Less than 80");
}
if else if
If condition returns false then we can add one more condition check by using else if.
int mark=76;
if ( mark >80) {
System.out.println("More than 80");
}
else if(mark>50) {
System.out.println("More than 50");
}
if else if else
Example
int mark=46;
if ( mark >80) {
System.out.println("More than 80");
}
else if(mark>50) {
System.out.println("More than 50");
}
else {
System.out.println("Less than 50");
}
Example
int mark=46;
if ( mark >=80) {
System.out.println("80 or more");
}
else if(mark>=50) {
System.out.println("50 or more");
}
else if(mark >=30 ){
System.out.println("30 or more");
}