Basic Operations in Java: Arithmetic and Logical

Ternary Operator in Java – How It Works and When to Use It

1/1

Given:

class Hexy {
    public static void main(String[] args) {
        Integer i = 42;
        String s = (i < 40) ? "life" : (i > 50) ? "universe" : "everything";
        System.out.println(s);
    }
}

What is the result?

Comments