[java/en] adding an exemple to ternary operator ?: (#2794)

We could think we always had to use = with ?:
This commit is contained in:
Mathieu Gemard 2017-07-11 11:08:23 +02:00 committed by ven
parent df6f8630a3
commit e9bb96aaa1

View File

@ -463,7 +463,11 @@ public class LearnJava {
// <second value>"
int foo = 5;
String bar = (foo < 10) ? "A" : "B";
System.out.println(bar); // Prints A, because the statement is true
System.out.println("bar : " + bar); // Prints "bar : A", because the
// statement is true.
// Or simply
System.out.println("bar : " + (foo < 10 ? "A" : "B"));
////////////////////////////////////////
// Converting Data Types