Loading

Program to find the largest among three numbers by simple comparison operators(nested if-else):                                                 

package quipoin.javaeasyprograms;
import java.util.Scanner;

public class MaximumNum {

	static double findGreatestBetweenThree(double x, double y, double z) {
		if (x > y) {
			if (x > z)
				return x;
			else
				return z;
		} else if (y > z) {
			return y;
		} else if (z > y) {
			return z;
		}
		return -1;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("Enter the three number:");
		double a = sc.nextDouble();
		double b = sc.nextDouble();
		double c = sc.nextDouble();
		System.out.println(findGreatestBetweenThree(a, b, c));
		sc.close();
	}
}

Output:

Enter the three number:
5.2
6.1
0.2
6.1