De Morgan's Law:
!A && !B == !(A || B);
!A || !B == !(A && B);
Find more info here:
http://fcmail.aisd.net/~JABEL/1DeMorgansLaw.htm
Conditional Statements
Annotations:
If/then statements
switch statements
See more:
https://www.inf.unibz.it/~calvanese/teaching/04-05-ip/lecture-notes/uni05.pdf
If/Then
statements
Annotations:
Syntax:
if(condition){
statements
}
see more:
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html
Multiple else/if
Annotations:
syntax:
if(condition){
statements;
}
else if(condition){
statements;
}
... //as many as you need
else{
statements;
}
nested if statement
Annotations:
Nested if statements are if statements within if statements. There also can be else statements within these. Pair up the ifs and else's by having the pair closest line up if they are in the same brackets. Try starting with the inner ifs Then pair the outer ones.
Ex:
if(condition){ //pairs with last
if(condition){ //pairs with 1st
}
else{ //1st else
}
}
else{ //last else
}
see more:
https://www.cs.umd.edu/~clin/MoreJava/ControlFlow/nested-if.html
Switch Statements
Annotations:
syntax:
switch(variable){
case value: statements;
break; //optional
...
}
see more:
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html
Valid data types
Annotations:
You can use a byte, short, char, int or String(Java 7+ only). You can also use other "wrapper" classes that hold these values, such as Character, Byte, Short, Integer. These will be used later in the year.
See more:
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html
Case Groups
Annotations:
if there is no statements after a case, the next statements after a case will be used instead. This means multiple conditions can be used for the same statement.
Example:
int test = 2;
switch(test){
case 1:
case 2:
case 3: System.out.println("test < 4");
break;
case 4:
case 5: System.out.println("test >3");
break;
}
This shows how multiple values can be used for one statement within a switch.
For another example, look toward the bottom of this page:
http://www.dummies.com/how-to/content/switch-statements-in-java.html
Break
Annotations:
break within a switch statement exits the rest of the switch statement once hit. Without a break in a switch, it will keep running through the cases even if another has already been activated. Here's an example of when it would be useful to include a break:
http://stackoverflow.com/questions/2710300/why-do-we-need-break-after-case-statements
Default
Annotations:
"case default:" is used at the end of a switch and always runs at the end if the switch hasn't broken. It is usually used to let the user know that the variable tested didn't meet any of the case values.
See here for explanations and a small exersice:
http://www.homeandlearn.co.uk/java/java_switch_statements.html