Java program to find the largest in three numbers using nested if

Let’s learn largest number in java or java program to find the largest in three numbers using nested if.

java program to find largest of three numbers using nested if

Java program to find the largest in three numbers using nested if

Biggest number in java is the most common java interview question.

In the below java program rather checking a condition in single if else statement we use nested if to find largest in three numbers.

Also read – preface to java virtual machine and architecture

Here’s the java program to find largest number in java.

public class LargestNestedIfDemo 
{
public static void main(String[] args)
{
int num1 = 36, num2 = 35, num3 = 56;
if(num1 >= num2)
{
if(num1 >= num3)
{
System.out.println(num1 + " is largest number.");
}
else
{
System.out.println(num3 + " is largest number.");
}
}
else
{
if(num2 >= num3)
{
System.out.println(num2 + " is largest number.");
}
else
{
System.out.println(num3 + " is largest number.");
}
}
}
}

Output:

56 is largest number.