Java Examples
Java ExamplesPrograms with output

Java Program to find Largest among three Numbers


Example:
import java.util.Scanner;
public class LargestThreeNumbers 
{
    public static void main(String[] args) 
    {

        int num1, num2, num3, largest;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter three numbers: ");
        num1=sc.nextInt();
        num2=sc.nextInt();
        num3=sc.nextInt();

            if(num1>=num2 && num1>=num3) 
            {
                System.out.println("Largest number: "+num1);
            }
            if(num2>=num1 && num2>=num3) 
            {
                System.out.println("Largest number: "+num2);
            }
            if(num3>=num1 && num3>=num2) 
            {
                System.out.println("Largest number: "+num3);
            }
    }
 }
Output:
Enter three numbers:
10
20
30
Largest number: 30

Share this page on:

Was this page helpful ?

Let us know how we did!

Subscribe Email Updates

to get latest update