Java greater than – Java Program on Greater Than and Less Than Operator

Java greater than: In the previous article, we have discussed about Java Program on Equal To and Not Equal To Operator

In this article we will see the use of Greater Than and Less Than operators in Java programming language.

Java Program on Greater Than and Less Than Operator

Greater Than operator:

Less than equal to java: Greater Than operator is used to check if value of left hand operand is greater than the value of right hand operand. It is represented by the symbol >. It is a relational operator and returns Boolean value True or False.

Program:

import java.util.Scanner;

class Main
{
    public static void main(String[] args)
    {
        //Scanner class object created
        Scanner in=new Scanner(System.in);
        //Taking input of 2 numbers
        System.out.println("Enter any two numbers: ");
        int n1=in.nextInt();
        int n2=in.nextInt();
        //checking if first value is greater than second value
        if(n1>n2)
        {
        	System.out.println("n1 value is greater than n2 value.");
        }
        else
        {
          	System.out.println("n1 value is not greater than n2 value.");  
        }

    }
}
Output:

Case-1
Enter any two numbers: 
567
456
n1 value is greater than n2 value.

Case-2
Enter any two numbers: 
222
456
n1 value is not greater than n2 value.

Less Than operator:

Java less than or equal: Less Than operator is used to check if value of left hand operand is less than the value of right hand operand. It is represented by the symbol <. It is a relational operator and returns Boolean value True or False.

Program:

import java.util.Scanner;

class Main
{
    public static void main(String[] args)
    {
        //Scanner class object created
        Scanner in=new Scanner(System.in);
        //Taking input of 2 numbers
        System.out.println("Enter any two numbers: ");
        int n1=in.nextInt();
        int n2=in.nextInt();
        //checking if first value is less than second value
        if(n1<n2)
        {
        	System.out.println("n1 value is less than n2 value.");
        }
        else
        {
          	System.out.println("n1 value is not less than n2 value.");  
        }

    }
}
Output:

Case-1
Enter any two numbers: 
5
9
n1 value is less than n2 value.

Case-2
Enter any two numbers: 
15
9
n1 value is not less than n2 value.

Are you wondering how to seek help from subject matter experts and learn the Java language? Go with these Basic Java Programming Examples and try to code all of them on your own then check with the exact code provided by expert programmers.

Related Java Programs: