Page 228 - Introduction to Programming with Java: A Problem Solving Approach
P. 228

                194 Chapter 5 Using Pre-Built Methods
10. Statement that prints the total number of dots on a thrown pair of dice:
System.out.println(2 + (int) (6 * (Math.random())) +
(int) (6 * (Math.random())));
11. Program that prints five random boolean values with seed 123L: import java.util.Random;
public class RandomBoolean
{
public static void main(String[] args)
{
}
Random random = new Random(123L);
for (int i=0; i<5; i++)
false
true
Apago PDF Enhancer
false
false
{
}
System.out.println(random.nextBoolean());
// end main
} // end RandomBoolean
The values are:
true











































































   226   227   228   229   230