codescracker


java

Java Program to Find Largest of Three Numbers



« Previous Program Next Program »


Find Largest of Three Numbers

To find the largest number of/in three numbers in Java Programming, you have to ask to the user to enter the three numbers, now start checking which one is the largest number, after finding the largest number, display that number as the largest number of the three number on the screen as shown in the following program.

Java Programming Code to Find Largest of Three Numbers

Following Java Program ask the user to enter the three numbers to check which one is the largest/biggest of the three numbers, then display the result on the screen :

/* Java Program Example - Find Largest of Three Numbers */
		
import java.util.Scanner;

public class JavaProgram
{
    public static void main(String args[])
    {
        int a, b, c, big;
        Scanner scan = new Scanner(System.in);
		
        System.out.print("Enter Three Numbers : ");
        a = scan.nextInt();
        b = scan.nextInt();
        c = scan.nextInt();
        
        // let a is the largest
        
        big = a;
        
        if(big<b)
        {
            if(b>c)
            {
                big = b;
            }
            else
            {
                big = c;
            }
        }
        else if(big<c)
        {
            if(c>b)
            {
                big = c;
            }
            else
            {
                big = b;
            }
        }
        else
        {
            big = a;
        }
		
        System.out.print("Largest Number is " +big);
    }
}

When the above Java Program is compile and executed, it will produce the following output. Above Java Programming Example Output (largest = c):

Java Program find largest of three numbers

Above Java Programming Example Output (largest = b):

Java Program find largest in three numbers

Above Java Programming Example Output (largest = a):

Java Program find largest from three numbers

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test