Write a program in Java to find maximum of three numbers using conditional operator.

 

AIM:   Write a program in Java to find maximum of three numbers using conditional operator.

 

CODE:

public class max

{

            public static void main(String args[])

            {

                        int n1=Integer.parseInt(args[0]);

                        int n2=Integer.parseInt(args[1]);

                        int n3=Integer.parseInt(args[2]);

                        int max=0;

                        max=(n1>n2 && n1>n3)? n1:((n2>n3)?n2:n3);

                                    System.out.println("Max="+max);

            }

}

 

OUTPUT:



Comments

Popular posts from this blog

Write an application that illustrates method overriding in the same package and different packages. Also demonstrate accessibility rules in inside and outside packages

Describe abstract class called Shape which has three subclasses say Triangle, Rectangle, and Circle. Define one method area()in the abstract class and override this area() in these three subclasses to calculate for specific object.

Write a program that illustrates interface inheritance. Interface P12 inherits from both P1 and P2. Each interface declares one constant and one method. The class Q implements P12. Instantiate Q and invoke each of its methods. Each method displays one of the constants.