Java Conditionals
// De Morgan's Law Demonstration
if (!(true && false)) { // if NOT (true AND false)
System.out.println("1st True");
}
if (false || true) { //simplfied version of above condition. if false OR true
System.out.println("2nd True");
}
/* According to De Morgan's law, a NOT condition will turn an AND into an OR and an OR into an AND.
The two conditon above are the same condition. */
if (!(false && !false)) { // if NOT (false AND NOT(false))
System.out.println("3rd True");
}
if (true || true) { // simplified version of above condition. if true OR true
System.out.println("4th True");
}
if (!(true || true)) { // this last one does not display because the OR switches to an AND and the trues switch to falses
System.out.println("5th True");
}
// If, Else If, Else Demonstration
if (1 == 1) { // if 1 is 1 (it always is) display true
System.out.println("This is true");
}
if (1 == 2) { // 1 is not 2 so this is ignored
System.out.println("This won't display");
}
else if (2 == 2){
System.out.println("This one's also true");
}
if (1 == 2) { // Non-true statement
System.out.println("This isn't true");
}
else if (1 == 3) { // Non-true statement
System.out.println("This isn't either");
}
else { // Because no other statements were true, this is the last response
System.out.println("Nothing else was true, so this is the reponse if nothing else works.");
}