mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
[java/en] adding an exemple to ternary operator ?: (#2794)
We could think we always had to use = with ?:
This commit is contained in:
parent
df6f8630a3
commit
e9bb96aaa1
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user