Lesser 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

Lesser Than Operator Example Program

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

Sample Output

Output is:
Enter any two numbers to check which is smaller:
45
78
num1 is smaller