Start Coding Now
🌱 Beginner Programsbeginner1 methods

Find Largest of Three Numbers in Java

Java program to find the largest among three numbers using if-else-if ladder.

Last updated: 11 January 2026

Method 1: Using If-Else

Comparing all possibilities.

public class Largest {
    public static void main(String[] args) {
        double n1 = -4.5, n2 = 3.9, n3 = 5.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.");
    }
}
Output:
5.5 is the largest number.

Explanation

We check if n1 is >= others, then n2. If both false, n3 is largest.

Frequently Asked Questions

Try This Program

Copy this code and run it in our free online Java compiler.

Open Java Compiler