We Offer 100% Job Guarantee Courses (Any Degree / Diploma Candidates / Year GAP / Non-IT / Any Passed Outs). Placement Records
Hire Talent (HR):+91-9707 240 250


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

Besant Technologies WhatsApp