Java Programming

If Statement in Java ( Learn in 2 mins )

Suppose we want to test any simple condition in our program then what we do for it. In this post, I will try to explain that how to test a simple condition in our program.

If Statement in Java

Java if statement is a branching statement which is used to test any simple condition in the program. A simple if statement must have two conditions i.e., true or false

In simple words, using if statement we can test the condition according to our requirement i.e., if the given statement got matched then the statement becomes true and the statement given as true will be executed otherwise the next condition will get executed.

If statement java


Syntax of if statement

if(test expression)
statement x;

The syntax of if statement is pretty simple. It just requires one condition to test i.e., test expression and it the condition becomes true then statement1 will be executed otherwise it will go out of scope.

Example of if statement

Consider an example to test any given number is greater than 5 or not.

class test
  public static void main(String args[])
   int a=7;
   system.out.print("Testing the condition");



-> If else statement

-> Nested if…else statement

-> If…else ladder

Leave a Reply