Merge pull request #343 from mix3d/patch-3

Added '?' conditional logic example
This commit is contained in:
Adam Bard 2013-09-13 10:14:19 -07:00
commit b1a70dd998

View File

@ -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
--- ---
@ -246,6 +247,13 @@ public class LearnJava {
} }
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
/////////////////////////////////////// ///////////////////////////////////////
// Converting Data Types And Typcasting // Converting Data Types And Typcasting