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

Let’s learn 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

Here’s the java program to find largest of three numbers using nested if,

Also read – largest using ternary operator

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.