Find Largest Of 3 Numbers Using "Nested-If" | Java Programs

Output:

*** Largest of 3 Number Using Nested If ***

The Three Numbers are: 103, 120, 70.

The largest number is: 120

Click Here For Java Online Compiler

Solution:

public class LargestOf3NumbersUsingNestedIf {

    public static void main(String[] args) {

        int num1 = 103, num2 = 120, num3 = 70;
        System.out.println("*** Largest of 3 Number Using Nested If ***" + "\n");
        System.out.println("The Three Numbers are: " + num1 + ", " + num2 + ", " + num3 + ".");
        System.out.println();

        if (num1 >= num2) {

            if (num1 >= num3) {
                System.out.println("The largest number is: " + num1);
            } else {
                System.out.println("The largest number is: " + num3);
            }
        } else {

            if (num2 >= num3) {
                System.out.println("The largest number is: " + num2);
            } else {
                System.out.println("The largest number is: " + num3);
            }
        }
    }
}
Share This :

Related Post



sentiment_satisfied Emoticon