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 Java Program with class Rectangle having instance variable width, length, area and colour. Create methods like setData() and area().Create two object of Rectangle and compare their area and colour. If area and colour both are the same for the objects then display “Matching Rectangles”, otherwise display “Non matching Rectangle”.