Algorithm


1. Start
2. Read three numbers (num1, num2, num3) from the user
3. Set a variable max to store the maximum value

4. If num1 is greater than num2 and num1 is greater than num3:
     4.1 Set max to num1
5. Else if num2 is greater than num1 and num2 is greater than num3:
     5.1 Set max to num2
6. Else:
     6.1 Set max to num3

7. Print the value of max as the largest number
8. End

Code Examples

#1 Code Example- Find Largest Among three numbers using if..else statement

Code - Java Programming

public class Largest {

    public static void main(String[] args) {

        double n1 = -4.5, n2 = 3.9, n3 = 2.5;

        if( n1 >= n2 && n1 >= n3)
            System.out.println(n1 + " is the largest number.");

        else if (n2 >= n1 && n2 >= n3)
            System.out.println(n2 + " is the largest number.");

        else
            System.out.println(n3 + " is the largest number.");
    }
}
Copy The Code & Try With Live Editor

Output

x
+
cmd
3.9 is the largest number.

#2 Code Example- Find the largest number among three using nested if..else statement

Code - Java Programming

public class Largest {

    public static void main(String[] args) {

        double n1 = -4.5, n2 = 3.9, n3 = 5.5;

        if(n1 >= n2) {
            if(n1 >= n3)
                System.out.println(n1 + " is the largest number.");
            else
                System.out.println(n3 + " is the largest number.");
        } else {
            if(n2 >= n3)
                System.out.println(n2 + " is the largest number.");
            else
                System.out.println(n3 + " is the largest number.");
        }
    }
}
Copy The Code & Try With Live Editor

Output

x
+
cmd
5.5 is the largest number.
Advertisements

Demonstration


Java Programing Example to Find the Largest Among Three Numbers-DevsEnv