codescracker


java

Java Program to Find Largest of Two Numbers



« Previous Program Next Program »


Find Largest of Two Numbers

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

Java Programming Code to Find Largest of Two Numbers

Following Java Program ask the user to enter the two numbers, to find the greatest/largest between the two numbers, then display the result on the screen:

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

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

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

Java Program find largest of two numbers

Above Java Programming Example Output (largest = a):

Java Program find largest in two 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