Return to Snippet

Revision: 50456
at August 23, 2011 06:56 by m1b


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

Initial URL

                                

Initial Description

                                

Initial Title
Java Ternary operator associativity demo

Initial Tags
java

Initial Language
Java