Java Program To Find Largest Between Three Numbers

Sharing is healthy !!

Today you will learn java program to find largest between three numbers. Here in the example scanner class is used to take input from the user. Let’s see the code implementation,

EXAMPLE: Java Program To Find Largest Between Three Numbers

Java Program To Find Largest Between Three Numbers

Also Read¬†–¬†Java Program To Find Even Or Odd

import java.util.Scanner;

public class Largest_Of_Three {

public static void main(String[] args) {

int a;
int b;
int c;

System.out.println("Enter three numbers to find the largest: ");
Scanner sc = new Scanner(System.in);

a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();

if(a > b && a > c)
{
System.out.println("First number is largest.");
}
else if(b > a && b > c)
{
System.out.println("Second number is largest.");
}
else if(c > a && c > b)
{
System.out.println("Third number is largest.");
}
else
{
System.out.println("Either numbers are not distinct.");
}
}
}

Output:

Enter three numbers to find the largest: 34 76 86
Third number is largest.

Sharing is healthy !!

Leave a Reply

Your email address will not be published.