Write a program in java to find to greatest and smallest number between three number?

class GreatestSmallest

{

                public static void main(String arg[])

                {

                                int a=5,b=7,c=9;

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

                                {

                                                System.out.println("Greatest Number "+a);

                                                if(b>c)

                                                                System.out.println("Smallest Number "+c);

                                                else

                                                                System.out.println("Smallest Number "+b);

                                }

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

                                {

                                                System.out.println("Greatest Number "+b);

                                                if(a>c)

                                                                System.out.println("Smallest Number "+c);

                                                else

                                                                System.out.println("Smallest Number "+a);

                                }

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

                                {

                                                System.out.println("Greatest Number "+c);

                                                if(a>b)

                                                                System.out.println("Smallest Number "+b);

                                                else

                                                                System.out.println("Smallest Number "+a);

                                }

                }

}

Greatest & Smallest Number.PNG

, , , , , , , ,

Leave a Reply