# Write a Java Program to Find Largest of Three Numbers Using Nested IF

Write a  java program to find the largest of three numbers using a nested If Else statement. or Java Program to Find the Largest Between Three Numbers Using the Ternary operator or Java Program to Find the Biggest of 3 Numbers or the Biggest of three numbers using the Logical Operators in Java or How to find the largest of three Integers in Java. Write a C Program for finding the greatest number among the given three numbers.

To solve this problem we need to compare all three numbers to each other .for a better explanation we need three numbers to assume that numbers are 17, 45, and 56. ex-you have to give three numbers, a number may be Integer, Float, or Double your task is to find the Greatest number Input given by the user.

Step 1: First We Compare 17 to 45 and 56 if it is the Largest then we can say that 17 is the Largest else we go to the next step.

Step 2: Then we compare 45 to 56 and 17 if it is the Largest then we can say that 45 is the Largest else we go to the next step.

Step 3: Then we compare 56 to 45 and 17 if it is the Largest then we can say that 56 is the Largest else we go to the next step (Special Case).

Step 4: This is the last case if all numbers are the same or equal then it will print a message.

"All INPUT ARE EQUAL"

Read: C++ Program To Find Greater Number. Among Given Three Number

## Java Program to Find Largest of Three Numbers Using Nested IF

``````import java.util.Scanner;
/* gross salary program in java */
class GreatestAmongThree {

public static void main(String[] args) {
int num1, num2, num3;

Scanner scan = new Scanner(System.in);
System.out.println("Enter Three Numbers: ");

num1 = scan.nextInt();
num2 = scan.nextInt();
num3 = scan.nextInt();

if (num1 >= num2) {
if (num1 >= num3)
System.out.println(num1 + " is the largest number.");
else
System.out.println(num3 + " is the largest number.");
} else {
if (num2 >= num3)
System.out.println(num2 + " is the largest number.");
else
System.out.println(num3 + " is the largest number.");
}
}
}``````

### Java Program to Find Largest of Three Numbers Using Ternary Operator

``````import java.util.Scanner;
/* gross salary program in java */
class GreatestAmongThree {

public static void main(String[] args) {

int num1, num2, num3, Greatest;

Scanner scan = new Scanner(System.in);
System.out.println("Enter Three Numbers: ");

num1 = scan.nextInt();
num2 = scan.nextInt();
num3 = scan.nextInt();

Greatest = (num1 > num2) ? (num1 > num3 ? num1 : num3) : (num2 > num3 ? num2 : num3);
System.out.println("Greatest Number Is : " + Greatest);
}
}``````

Read: C Program To Find Greater Number. Among Given Three Number

### Similar to the Largest of the Three Numbers

Previous Post
Next Post

#### post written by: Ghanendra Yadav

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.