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

Hey guys!! Welcome to flower brackets blog. 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

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

`public class LargestIfElseDemo {   public static void main(String[] args)    {      int num1 = 54, num2 = 91, num3 = 65;      if(num1 >= num2 && num1 >= num3)      {         System.out.println(num1 + " is largest number.");      }      else if(num2 >= num1 && num2 >= num3)      {         System.out.println(num2 + " is largest number.");      }      else      {         System.out.println(num3 + " is largest number.");      }   }}`

Output:

91 is largest number.

Similarly we can use nested if else statement to find largest of three,

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.