Skip to content

Latest commit

 

History

History
23 lines (15 loc) · 429 Bytes

ternary.md

File metadata and controls

23 lines (15 loc) · 429 Bytes

Ternary operators

These are very similar to what you would use in JS with a little difference

public class Main {

    public static void main(String[] args) {

        int age = 37;

        String truthy = age > 20 ? "true":"false";

        System.out.println(truthy); // true
    }
}

The operator requires a variable / data type assigned to it like so:

String truthy = age > 20 ? "true":"false";