Chapter 9 Question 4 (Using the random class)

Chapter 9 Question 4 (Using the random class)

  • *9.4 (using the Random class) write a program to create a Random object with a seed of 1000, and then use the nextInt(100) method to display 50 random integers between 0 and 100.
    *9.4 (Using the random class) Write a program to create a random object with a seed of 1000, and then use the nextint (100) method to display 50 random integers between 0 and 100.
  • Reference Code:
package chapter09;

import java.util.Random;

public class Code_04 {
    
    
    public static void main(String[] args) {
    
    
        Random random = new Random(1000);
        for (int i = 0, n = 0; i < 50; i++, n++) {
    
    
            if(n % 10 == 0)
                System.out.println("");
            System.out.print(random.nextInt(100) + " ");
		}
	}
}

  • The results show that:
87 35 76 24 92 49 41 45 64 50 
79 59 72 83 36 75 46 2 23 41 
22 71 89 2 93 42 49 42 35 76 
32 0 52 95 87 31 99 18 79 2 
91 5 55 84 71 95 58 87 77 38 
Process finished with exit code 0

Guess you like

Origin blog.csdn.net/jxh1025_/article/details/109256974