Java | If - Else Statement: If - else statement is one of the conditional statement. if checks the condition, if condition is true if block executes otherwise else block executes.
Syntax: if ( condition )
{
// statements...
}
else
{
// statements...
}
Here is the Code:
- import java.io.*;
- class Main {
- public static void main (String[] args) {
- int i = 1;
- if( i % 2 == 0)
- {
- System.out.println("Even");
- }
- else
- {
- System.out.println("Odd");
- }
- int a = 1, b = 2;
- int min;
- if( a < b )
- {
- min = a;
- }
- else
- {
- min = b;
- }
- System.out.println("Min value is :" + min);
- }
- }
Output:
Odd
Min value is :1
Here is the Video: