Largest of Three Numbers

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.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 “Largest of Three Numbers”

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s