Skip to content

Instantly share code, notes, and snippets.

@RaynZayd
Created July 26, 2017 11:19
Show Gist options
  • Save RaynZayd/302c9e74af755eca8519189706b03ef7 to your computer and use it in GitHub Desktop.
Save RaynZayd/302c9e74af755eca8519189706b03ef7 to your computer and use it in GitHub Desktop.
/*This program tests if the condition is true and does something , otherwise do something else. It demonstrates the use of the short-hand ternary for conditions "?:" By Rayn Zayd */
/*This program tests if the condition is true and does something , otherwise do something else. It demonstrates the use of the short-hand ternary for conditions "?:"
By Rayn Zayd
*/
public class TestCondition{
public static void main(String[] args){
int value1 = 5;
int value2 = 10;
int result;
boolean thisCondition = false;//compiles when set to true and prints 5
result = thisCondition ? value1 : value2;
System.out.println(result);// prints 10 because "thisCondition" is false.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment