Posted By

m1b on 08/23/11


Tagged

java operator Ternary


Versions (?)

Java Ternary operator associativity demo


 / Published in: Java
 

  1. public class TernaryOp {
  2. public static void main(String[] args) {
  3. int i = Integer.parseInt(args[0]);
  4. System.out.printf("%ni=%s",
  5. // switch case with ternary op idiom:
  6. i == 1 ? "one"
  7. : i == 2 ? "two"
  8. : i == 3 ? "three"
  9. : "too many!"
  10. );
  11. }
  12. }

Report this snippet  

You need to login to post a comment.