OneBite.Dev - Coding blog in a bite size

use if conditional statement in java

Code snippet on how to use if conditional statement in java

int x = 5;
int y = 10;

if (x < y)
{
    System.out.println("x is less than y");
}

This is a simple code that demonstrates how to use an if conditional statement in Java. The first two lines define two integer variables a and b and assign them each a value. The third line is the if statement. This line is evaluating if x is less than y. If the condition is true, then the code inside the curly brackets will run. In this case, the program will print out “x is less than y”. If the condition is false, the code inside the curly brackets will not run and the program will move on to the next line of code.

java