Java Program to Find Largest of Three Numbers

In this tutorial, we will learn how to write a Java program to find the largest among the three numbers.
We will read input from the console using Scanner class.

Java Program to Find Largest of Three Numbers

package com.javaguides.java.tutorial;

import java.util.Scanner;

/**
 * Java Program to find largest of three Numbers
 * 
 * @author https://www.sourcecodeexamples.net/
 *
 */
public class JavaProgram {
    public static void main(String[] args) {

        try (Scanner scanner = new Scanner(System.in)) {
            int num1, num2, num3;
            System.out.print("Enter first number:");
            num1 = (int) scanner.nextInt();

            System.out.print("Enter second number:");
            num2 = (int) scanner.nextInt();

            System.out.print("Enter third number:");
            num3 = (int) scanner.nextInt();

            if (num1 >= num2 && num1 >= num3) {
                System.out.println(num1 + " is the largest Number");
            } else if (num2 >= num1 && num2 >= num3) {
                System.out.println(num2 + " is the largest Number");
            } else {
                System.out.println(num3 + " is the largest Number");
            }
        }
    }
}
Output:
Enter first number:50
Enter second number:20
Enter third number:60
60 is the largest Number

Related Java Programs

Free Spring Boot Tutorial - 5 Hours Full Course


Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course