This example illustrates how to use the if-else conditional statement in java.
The if-else statement is one of the widely used control flow statements while programming. It lets the program execute a set of statements enclosed within the "if" block only if the certain condition evaluates to true otherwise program executes statements of "else" block. So it provides the facility to the programmer to handle the condition based programming.
Source Code of ifelseDemo.java :
class ifelseDemo{ public static void main(String arg[]){ int i=5,j=10; if(i <j)
{
System.out.println("j is greater than i");
} else{
System.out.println("i is greater than j");
}
}
}
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.