COSI 11a Chapter Notes - Chapter 5: Texas State Highway Loop 1, Operand, Institute For Operations Research And The Management Sciences
![](https://new-preview-html.oneclass.com/Yaxkv7zyB48qN4baXr7em20dL5M6XOgn/bg1.png)
Chapter 5 Outline
Program Logic and Indefinite Loops
Pages 301 – 372
I. The while Loop
A. Random Numbers
1. Math.random() can be used to obtain a number between 0 and 1, including 0 but not including
1.
2. The java.util package contains a random class with methods nextInt(), nextInt(max),
nextDouble(), and nextBoolean(). The nextInt method is passed a maximum number from which
0 (inclusive) to max (exclusive) the random number is chosen. To use the random class, a
random object must be created:
Random r = new Random();
B. do/while Loop
1. do/while loops are useful when you have to execute a loop at least once.
II. The Boolean Type
A. Logical Operators
1. The NOT operator (!) reverses the value of the operand, such as !(2==2) resulting in false.
III. User Errors
A. Scanner Lookahead
1. Every next method in the Scanner class has a corresponding has method.
2. The has method of the Scanner class informs the user whether or not the operation can be
performed.
find more resources at oneclass.com
find more resources at oneclass.com