util.md 509 字节
Newer Older
湘王's avatar
湘王 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
# 工具类

如果想实现1~10之间的随机数,下面哪个代码可以实现:

## 答案

A

## 选项

### A

```Java

Random random = new Random();
int result = random.nextInt(10);
result = result + 1;
```

### B

```Java

Random random = new Random();
int result = random.nextInt(1);
result = result + 10;
```

### C

```Java

int max = 10;
int min = 1;
Random random = new Random();
int result = random.nextInt(min) % (max - min + 1) + min;
System.out.println(result);
```

### D

以上都是