[Java] Largest of Three Numbers Java Program

This java program is to easily find out largest number in three integers values. But that is not optimize way if numbers are more than that better follow other algorithms.

lass LargestOfThreeNumbers {
public static void main(String args[]) {
int x, y, z;

Scanner in = new Scanner(System.in);
System.out.println("Please Enter First integer");
x = in.nextInt();
System.out.println("Please Enter Second integer");
y = in.nextInt();
System.out.println("Please Enter Third integer");
z = in.nextInt();

if (x > y && x > z)
System.out.println("First number is largest.");
else if (y > x && y > z)
System.out.println("Second number is largest.");
else if (z > x && z > y)
System.out.println("Third number is largest.");
System.out.println("Entered numbers are not distinct.");


Please Enter First integer
Please Enter Second integer
Please Enter Third integer
Second number is largest.


For more Algorithms and Java Programing Test questions and sample code follow below links

One thought on “[Java] Largest of Three Numbers Java Program”