Program to find largest number among three numbers

Program to find largest number among three numbers

Java program to display the big number where the user enters three numbers 

import java.util.*;

public class BigNumberPrint

{

    public static void main(String[] args)

    {

        int num1;                       // First Number

              int num2;                 // Second Number

        int num3;                       // Third Number

        int big;                // Store the largest number.

 

        // Scanner Object sc.

        Scanner sc = new Scanner(System.in);

 

        // Input the First number from the user.

        System.out.print("Enter first number: ");

        num1 = sc.nextInt();

              // Input the Second number from the user.

        System.out.print("Enter second number: ");

        num2 = sc.nextInt();

              // Input the Third number from the user.

        System.out.print("Enter third number: ");

        num3 = sc.nextInt();

 

        // Find the largest number among three number.

        if (num1 > num2 && num1 > num3)

        {

            big = num1;

        }

        else if (num2 > num3)

        {

            big = num2;

        }

        else

        {

            big = num3;

        }

 

        // Display a big number.

        System.out.println("Big number: " + big);

    }

} 

Output

Enter first number: 5

Enter second number: 8

Enter third number: 2

Largest number: 8

Program to find the largest number among three numbers

import java.util.*;

public class LargeNumberPrint

{

    public static void main(String[] args)

    {

        int num1;                       // Input First Number

        int num2;                       // Input Second Number

        int num3;                       // Input Third Number

        int large;                        // Store the largest number.

 

        // Scanner Object sc.

        Scanner sc = new Scanner(System.in);

 

        // Input the First number from the user.

        System.out.print("Enter first number: ");

        num1 = sc.nextInt();

        // Input Second number from the user.

        System.out.print("Enter second number: ");

        num2 = sc.nextInt();

        // Input Third number from the user.

        System.out.print("Enter third number: ");

        num3 = sc.nextInt();

        // Find the largest number among three numbers.

        if(num1 >= num2)

        { 

            if(num1 >= num3)

                large = num1;

            else

                large = num3; 

        }

        else

        {

            if(num2 >= num3)

                large = num2;

            else

                large = num3;

        }

        // Print the large number.

        System.out.println("Largest number: " + large);

    }

}

Output

Enter first number: 6

Enter second number: 9

Enter third number: 2

Largest number: 9

 More Java Program

Happy number in java

Celsius to Fahrenheit In Java – Fahrenheit To Celsius In Java

Magic number | Magic number in java


SHARE THIS
Previous Post
Next Post