Find Maximum of Three Numbers:

public class MaxOfThreeNumbers {

 public static void main(String[] args) {

 int num1 = 10, num2 = 20, num3 = 15, max;

 max = (num1 > num2) ? (num1 > num3 ? num1 : num3) : (num2 > num3 ? num2 : num3);

 System.out.println(“Maximum of ” + num1 + “, ” + num2 + “, and ” + num3 + ” is: ” + max);

 }

Output:

Maximum of 10, 20, and 15 is: 20

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *