vendredi 24 juillet 2020

Why doesn't Java allow the use of a ternary operator here? [duplicate]

Instead of typing :

if (Math.random() < .5) {
    System.out.println("toto");
} else {
    System.out.println("tata");
}

I would find it useful, and logical, to type instead :

Math.random() < .5 ? System.out.println("toto") : System.out.println("tata");

However, I get the error not a statement. I don't understand how this is an issue.

Aucun commentaire:

Enregistrer un commentaire