tampurus

2 Greatest of two and three number using ternary operator

Apr 2nd, 2022 (edited)
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.40 KB | None | 0 0
  1. // Q 3,6
  2. public class Main
  3. {
  4.     public static void main(String[] args) {
  5.         int a = 5, b = 1 , c = 10;
  6.         int max_two = (a>b) ? a : b;
  7.         int max_three = (a>b) ? (a>c ? a : c) : b;
  8.         System.out.println("Greatest of two number is "+max_two);
  9.         System.out.println("Greatest of three number is "+max_three);
  10.     }    
  11. }
  12. /*
  13. Output
  14. Greatest of two number is 5
  15. Greatest of three number is 10
  16. */
Add Comment
Please, Sign In to add comment