mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-04-26 23:23:55 +00:00
Added '?' conditional logic example
Also added myself as a contributor.
This commit is contained in:
parent
a4b20388af
commit
338862e732
@ -3,6 +3,7 @@
|
|||||||
language: java
|
language: java
|
||||||
contributors:
|
contributors:
|
||||||
- ["Jake Prather", "http://github.com/JakeHP"]
|
- ["Jake Prather", "http://github.com/JakeHP"]
|
||||||
|
- ["Madison Dickson", "http://github.com/mix3d"]
|
||||||
filename: LearnJava.java
|
filename: LearnJava.java
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -245,6 +246,13 @@ public class LearnJava {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
System.out.println("Switch Case Result: " + monthString);
|
System.out.println("Switch Case Result: " + monthString);
|
||||||
|
|
||||||
|
// Conditional Shorthand
|
||||||
|
// You can use the '?' operator for quick assignments or logic forks.
|
||||||
|
// Reads as "If (statement) is true, use <first value>, otherwise, use <second value>"
|
||||||
|
int foo = 5
|
||||||
|
String bar = (foo < 10) ? "A" : "B";
|
||||||
|
System.out.println(bar); // Prints A, because the statement is true
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user