Java Program to Find the Largest Among Three Numbers

Write a program to find the largest among three numbers.

This program demonstrated about use of ‘if’ with ‘else If’ statement.

public class LargestAmongThree {

    public static void main(String[] args) {

        double num1 = -4.0, num2 = 4.1, num3 = 2.4;

        if( num1 >= num2 && num1 >= num3)
            System.out.println(num1 + " is the largest.");

        else if (num2 >= num1 && num2 >= num3)
            System.out.println(num2 + " is the largest.");

        else
            System.out.println(num3 + " is the largest.");
    }
}
Output
4.1 is the largest.

Leave a Reply