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.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.");
		else
			System.out.println("Entered numbers are not distinct.");
	}
}

Output

Please Enter First integer
10
Please Enter Second integer
20
Please Enter Third integer
5
Second number is largest.

More

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

Advertisements

One thought on “Largest of Three Numbers”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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