Lecture 7, CS 302-7 and 8, February 6
i. Shortcut for importing everything from java.util (Random and Scanner):
1.
import
java.util.* ;
i. scanner.next() gets one word
ii. scanner.nextLine() – whole line (multiple words)
i. int count=Integer.parseInt(string)
ii. double price=Double.parseDouble(string)
iii. If not valid translation, run-time error
1. Integer.parseInt(“Hello World!”);
i. theString.charAt()
ii. Counts begin at zero
i. theString=”STRING”
ii. theString.substring(1,4)=”TRI”
if (condition) {
//do this;
}
else
{
//do that;
}
i. {}
1. Not necessary if we only have one statement after the if or else
2. However, it is good form to always use them
ii. There is no ; after the if/else
i. Once again, we have block-structured code
ii. Indentation is not an accident – helps us keep track
i. == tests for equality between two values
i. >, >=, < , <=, ==,!=
ii. Note difference between = and ==
1. = assigns, == tests equality