Java Program to find largest of three numbers using nested if


In this program, You will learn how to find largest of three numbers using nested if statement in Java.


10 20 30 => 30

40 20 30 => 40


Example: How to find largest of three numbers using nested if in Java

Run it Now
import java.util.Scanner;

class Main {
    public static void main(String args[]) {

        int a, b, c;
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter Three Numbers :");
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();

        if (a > b) {
            if (a > c) {
                System.out.print("\nLargest is :" + a);
            } else {
                System.out.print("\nLargest is :" + c);
            }
        } else {
            if (b > c) {
                System.out.print("\nLargest is :" + b);
            } else {
                System.out.print("\nLargest is :" + c);
            }
        }

    }
}

Output:

Enter Three Numbers :12 10 30
Largest is :30