day07-random类的使用与练习

This commit is contained in:
2025-12-29 11:39:17 +08:00
parent 268fa720bf
commit cc9b5436b5
3 changed files with 58 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
package com.inmind.random02;
import java.util.Random;
/*
获取10个55~66之间的值包含55和66
random.nextInt(10);//获取0~9的随机数
*/
public class Demo06 {
public static void main(String[] args) {
Random random = new Random();
for (int i = 0; i < 1000; i++) {
int result = random.nextInt(12)+55;//0~9: 55~66 -55 -->0~11--->12
System.out.println(result);
}
}
}