用java使用Random类生成一个包含100个1000以内整数的数组,将其中能够被6整除的数拷贝到另一个数组中。
时间: 2023-05-23 17:06:20 浏览: 41
A:
```java
import java.util.Random;
public class Main {
public static void main(String[] args) {
// 创建一个包含100个1000以内整数的数组
int[] arr1 = new int[100];
Random random = new Random();
for (int i = 0; i < arr1.length; i++) {
arr1[i] = random.nextInt(1000) + 1;
}
// 打印原数组
System.out.println("原数组:");
for (int num : arr1) {
System.out.print(num + " ");
}
// 拷贝能够被6整除的数到新数组中
int[] arr2 = new int[arr1.length];
int count = 0;
for (int num : arr1) {
if (num % 6 == 0) {
arr2[count] = num;
count++;
}
}
// 打印新数组
System.out.println("\n能够被6整除的数:");
for (int i = 0; i < count; i++) {
System.out.print(arr2[i] + " ");
}
}
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)