logo image

Java program to find largest number from given 2 numbers



Following program shows you how to find largest number from given 2 numbers. In this program we get inputs from user and shows largest number from given two numbers using if condition

import java.util.Scanner;

public class BasicMath2 {

	public static void main(String[] args) {

		int input1;
		int input2;

		System.out.println("Enter two numbers:");

		Scanner in = new Scanner(System.in);
		input1 = in.nextInt();
		input2 = in.nextInt();

		if (input1 == input2) {
			System.out.println(input1 + " is equal to " + input2);

		} else if (input1 > input2) {
			System.out.println(input1 + " is larger than " + input2);

		} else {
			System.out.println(input1 + " is lesser than " + input2);

		}
	}
}

Output:

Example1:

Enter two numbers:
30
30
30 is equal to 30

Example2:

Enter two numbers:
50
10
50 is larger than 10

Example3:

Enter two numbers:
40
100
40 is lesser than 100