In this tutorial you will learn about the Java If Statement and its application with practical example.
Java if statement
Java if statement allows a block of code to be executed only when a specified condition is true. An if statement evaluates a boolean expression followed by one or more statements. The given boolean expression results in a boolean value that can only be either true or false.
Java If Statement Flow Diagram
Syntax:-
1 2 3 |
if(condition){ // statements } |
Here, a condition is a Boolean expression that results in either True or False, if it results in True then statements inside the body is executed, if it results in False then execution is skipped from if body.
Example:-
1 2 3 4 5 6 7 8 9 10 11 |
public class Main { public static void main(String[] args) { int num = 75; System.out.println("W3Adda - Java If Statement"); if(num > 50) { System.out.println("Number Greater than 50"); } } } |
Output:-