Greater Than Operator Example Java Program

Definition

Operators in Java are similar to those in C++. However, there is no delete operator due to garbage collection mechanisms in Java, and there are no operations on pointers since Java does not support them. Greater than operator checks if the value on the left side is greater than the value on the right side of the operator.

Syntax

a>b

Greater Than Operator Example Program

import java.util.Scanner;

class GreaterThanOperator{
	public static void main(String[] args){
		Scanner in=new Scanner(System.in);
		System.out.println("Enter any two numbers to check which is greater: ");
		int num1=in.nextInt();
		int num2=in.nextInt();
		if(num1>num2){
		System.out.println("num1 is greater");
		}
		else{
		System.out.println("num2 is greater");
		}
	}
}

Sample Output

Output is
Enter any two numbers to check which is greater:
34
45
num2 is greater