/************************************************** * Author: Morrison * Date created: 1 Sep 2020 * Date last modified: 1 Sep 2020 **************************************************/ public class Conditional { public Conditional() { } public static int abs(int x) { return x >= 0? x: -x; //ternary statement } public static double abs(double x) { return x >= 0? x: -x; //ternary statement } public static void main(String[] args) { //simple if /*int x = 15; if(x*x < 100) // if x*x < 100: { System.out.printf("The square of %s is less than 100", x); } if(x*x < 400) // if x*x < 100: { System.out.printf("The square of %s is less than 400\n", x); } else //else: { System.out.printf("The square of %s is greater than 400\n", x); } int age = 20; if(age >= 65) { System.out.println("You can apply for Social Security"); } else if(age >= 21) // elif age >= 21: { System.out.println("You can legally purchase alcohol."); } else if(age >= 18) { System.out.println("You can register to vote."); } else //this is optional { System.out.println("You have no adult rights or privileges."); }*/ //legal switch types: char, integer primitives, enums, String //illegal: doubles or floats int quack = 1; switch(quack) { case 0: System.out.println("zero"); break; //you need this or the rest of 'em run. case 1: System.out.println("one"); break; case 2: System.out.println("two"); break; case 3: System.out.println("three"); break; default: //error reporting cloaca System.out.println("not a choice"); } } }