Conditional Control Statement in JAVA

Control statement in java is IF statment. This if Statement use with condition and statement to execute. This IF statement is like other language having in C, forton 77 or C++.

This condition is a boolean expression here. This boolean either can be true or false. If boolean return true value, it IF statement execute next statement. If boolean expression return false, it stop execution of IF statement.

These expression are

< less than
> greater than
== equal to
!= not equal to
<= less than and equal to
>= greater than and equal to

Example of IFstatement is shown

public class IfStatement {
  public static void main(String[] args)
  {
      int a=5;
      int b=6;

      ///// less than statement
      if(a<b)
      {
          System.out.println("if statement with a less than b true");
      }
      else
      {
          System.out.println("else statement with a less than b false");
      }

      ///// greater than statement
      if(a>b)
      {
          System.out.println("if statement with a greater than b true");
      }
      else
      {
          System.out.println("else statement with a greater than b false");
      }

      ///// equal than statement
      if(a==b)
      {
          System.out.println("if statement with a equal b true");
      }
      else
      {
          System.out.println("else statement with a equal b false");
      }
  }
}

Output of Program

if statement with a less than b true
else statement with a greater than b false
else statement with a equal b false

Tags:

Bookmark  

 

Leave a Reply

Security Code:

 

  Random Post