if then Statement in Java
if then Statement in Java
If statement is a part of looping in java. It provides us the facility for test our condition and return the result in term of true and false.
Syntax:
If (condition) { //statements }
Example:
Public class Example { Public static void main (String args [] ){ //defining an 'age' variable int age=17; //checking the age if(age>18){ System.out.print("Age is greater than 18"); } } }
Here we are giving condition that if age is greater than 18 then only it should print “age is greater than 18”.
That is how we can evaluate a condition and based on its result execute some statement.
Points to remember:
- If you want to execute only one statement then {} are not required.
- you can give more than one condition in one if block.
- If condition will always return true or false.
Click Here-> Get Java Training with Real-time Projects