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

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

import java.util.*;

public class Code3 {

public static void main(String arg[]) {

int max, a, b, c;

Scanner sc = new Scanner(System.in);

System.out.print("Enter 1st Number: ");

a = sc.nextInt();

System.out.print("Enter 2nd Number: ");

b = sc.nextInt();

System.out.print("Enter 3rd Number: ");

c = sc.nextInt();

max = a > b ? (a > c ? a : c) : (b > c ? b : c);

System.out.println("\nMaximum number is " + max);

}

}

Comments

Popular posts from this blog

Write a program in Java to find second maximum of n numbers without using arrays