FINDING GREATEST NUMBER USING NESTED IF ELSE IN JAVA

Problem statement:- write a program to fing greatest among 3 number using is else in java

package Condition;
import java.util.Scanner;
public class NestedIfElse {
    public static void main(String[] args) {
    Scanner sc=new Scanner(System.in)
    int a=sc.nextInt();
    System.out.println("the first number is "+a);
    int b=sc.nextInt();
    System.out.println("the second number is "+b);
    int c=sc.nextInt();
    System.out.println("the third number is "+c);
    int result=0;
        if(a>b) {
            if(a>c) {System.out.println("a is greater");
        }
            else {
                System.out.println("c is greater");
            }
          
        }
        else {
            if(b>c)
            System.out.println("b is greater");
            else {
                System.out.println("c is greater");
            }
    }
    //short hand:-    result=a>b?a>c?a:c:b>c?b:c;
  }
}
output:-
45
the first number is 45
43
the second number is 43
56
the third number is 56
c is greater

Comments