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 the largest in three numbers using nested if

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

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

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

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.


Also read – operators in java