Don't let the Lockdown slow you Down - Enroll Now and Get 3 Course at 24,999/- Only. Explore Now!


if then statement in java

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.


If (condition)


Public class Example {
Public static void main (String args [] ){
//defining an 'age' variable
int age=17;
//checking the age
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

Scroll Up
Besant Technologies WhatsApp