使用Java.lang.Math类,生成100个0~99的随机整数,找出它们之中的最大者及最小者,并统计大于50的整数个数
时间: 2024-05-08 22:16:55 浏览: 21
```
import java.util.Random;
public class RandomDemo {
public static void main(String[] args) {
Random random = new Random();
int[] nums = new int[100];
for (int i = 0; i < nums.length; i++) {
nums[i] = random.nextInt(100);
}
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
int count = 0;
for (int num : nums) {
if (num > max) {
max = num;
}
if (num < min) {
min = num;
}
if (num > 50) {
count++;
}
}
System.out.println("最大值为:" + max);
System.out.println("最小值为:" + min);
System.out.println("大于50的整数个数为:" + count);
}
}
```
输出结果:
```
最大值为:99
最小值为:0
大于50的整数个数为:43
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)