-
User Errors
-
robust programs
- a prog can deal with illegal data
-
Scanner Lookahead
- hasNextInt();
- hasNextDouble();
- hasNextString();
- The prompt and error detection leads to "fencepost"
-
Assertions and Program Logic
- provable assertion
-
Reasoning about Assertions
- Program verification
- case study(write)
-
The boolean Type
-
statements
- boolean text1 = true;
- test1 = text2
- test 3 = (3*100 < 250);
-
logical operators
- NOT
- AND
- OR
-
Short-Circuited Evaluation
-
avoid exception
- while(stop < s.length() && s.charAt(stop)==' ')
-
Boolean Variables and Flags
- boolean variable=>assign a name
-
flag
- track the variable
-
Boolean Zen
- simplify boolean expression
-
De Morgan's laws
- p||q = !p&&!q
-
Fencepost Algorithms
-
Add initial output outside the loop
- if/else to this initial
- or double test
-
Sentinel Loops
- end input signal
-
The while loop
-
indefinite loops
- update step
- scope of variable
-
pseudorandom numbers
- Math.random()
-
Class Random (in java.util)
- nextInt(10);
- nextDouble();
- nextBoolean()
- save the random, if use again
- Priming a loop
-
do..while
- adapt to the prog you know you want to exe at least once