Java program to find largest number from given 3 numbers


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

import java.util.Scanner;

public class BasicMath3 {

	public static void main(String[] args) {

		int input1;
		int input2;
		int input3;

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

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

		if ((input1 == input2) && (input1 == input3)) {
			System.out.println("All numbers are equal");

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

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

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

		} 
	}
}

Output:

Example1:

Enter three numbers:
60
30
10
60 is larger than 30 and 10

Example2:

Enter three numbers:
20
20
20
All numbers are equal