summaryrefslogtreecommitdiffhomepage
path: root/java.html.markdown
diff options
context:
space:
mode:
authorMathieu Gemard <mathieu.gemard@gmail.com>2017-07-11 11:08:23 +0200
committerven <vendethiel@hotmail.fr>2017-07-11 11:08:23 +0200
commite9bb96aaa1d404509bb935ba1b95d34b5e74fd6c (patch)
treef3dadec00906248e69a048e1fa742bc09d2675ee /java.html.markdown
parentdf6f8630a373806bac5016bd7bebd25c140557b6 (diff)
[java/en] adding an exemple to ternary operator ?: (#2794)
We could think we always had to use = with ?:
Diffstat (limited to 'java.html.markdown')
-rw-r--r--java.html.markdown6
1 files changed, 5 insertions, 1 deletions
diff --git a/java.html.markdown b/java.html.markdown
index 9c60eabc..a27a68ca 100644
--- a/java.html.markdown
+++ b/java.html.markdown
@@ -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