if and else in java code example
Example 1: if else in java
import java.io.*;
public class JavaIfElse
{
public static void main(String[] args)
{
int number = 15;
if(number%2 == 0)
{
System.out.println(number + " is even number");
}
else
{
System.out.println(number + " is odd number");
}
}
}
Example 2: else statement java
int x = 3;
if (x == 3) {
} else {
}
Example 3: if statement java
int x = 3;
if (x == 3) {
}
Example 4: java if
if(a<b){
}else if(a==b){
}else{
}
Example 5: if else java
public class TestIfElse {
public static void main(String[] args) {
int a = 5, b = 6;
if (a > b) {
System.out.println("a is greater");
} else {
System.out.println("b is greater");
}
}
}
Example 6: java if ?
max = (a > b) ? a : b;