Lecture 9, CS 302-6, September 23
i. Java interpret its correctly, as an else (as though it is at the end of the switch)
ii. Will not compile if two default statements given, though
i.
!(x=y) ->
x!=y
ii.
!
(x>y) -> x<=y
i.
!(A
&& B)=>!A || !B
ii.
!(A || B)
=>!A && !B
i. If(quantity>0 && price/quantity)
1. analyze quantity>0 first, if it isn’t, don’t process price/quantity
ii. Why? Less processing, prevent divide by zero issues.
if(a)
if(b)
else
i. The else goes with the second if in the above case. But it’s best to avoid this syntax
i. Returns a random number between 0 inclusive and 2 exclusive, so either 0 or 1
i. Don’t do string1==string2
ii. Instead, do string1.equals(string2)
iii. string1.compareTo(string2)
1. 0 if equal, - if string 1 is before, + if string 1 is after alphabetically
iv.
XKCD
pointers - http://xkcd.com/138/
i. sqrt(2.0)^2!=2.0
i. Verifies that the next input is of the desired type
ii. Can be used in conditions for input data validation
while(condition)
{
do something
}
i. Be careful with <=, < etc in conditions