how to use if 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 and in java
if(x == 1 && y == 2){
println("x = 1 and y = 2");
}
Example 4: if statement java
int x = 3;
if (x == 3) {
}
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;