Finding the largest and the smallest number among three input numbers can be done with the help of “if, else if” statements. We could simply have use just if statements to find the output but that’s not correct. The difference is that if the first if is true, all of the other else ifs won't be executed, even if they do evaluate to true. If they were individual ifs, however, all of the ifs will be executed if they evaluate to true.


package program1;


public class Program1 {

    public static void main(String[] args)throws IOException {

        BufferedReader br=new BufferedReader(new InputStreamReader(;

        int a,b,c;


                    System.out.println("Enter first number");


                    System.out.println("Enter second number");


                    System.out.println("Enter third number");



                    if(a>=b && a>=c)

                        System.out.println("Largest number is "+ a);

                    else if(b>=a && b>=c)

                        System.out.println("Largest number is "+ b);

                    else if(c>=a && c>=b)

                        System.out.println("Largest number is "+ c);


                    if(a<=b && a<=c)

                        System.out.println("Smallest number is "+ a);

                    else if(b<=a && b<=c)

                        System.out.println("Smallest number is "+ b);

                    else if(c<=a && c<=b)

                        System.out.println("Smallest number is "+ c);        






It will generate the following output:

Enter first number


Enter second number


Enter third number


Largest number is 78

Smallest number is 23

  Modified On Mar-13-2018 05:32:00 AM

Leave Comment