java键盘录入数存到两组数组,输入数组一,输出数组二
时间: 2024-02-23 14:31:24 浏览: 63
java从键盘输入数组
以下是Java代码实现:
```java
import java.util.Scanner;
public class InputOutputArrays {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入数组的长度:");
int length = scanner.nextInt();
int[] inputArray = new int[length];
int[] outputArray = new int[length];
System.out.println("请逐个输入数组元素:");
for (int i = 0; i < length; i++) {
inputArray[i] = scanner.nextInt();
outputArray[i] = inputArray[i];
}
System.out.println("输入数组为:");
for (int i = 0; i < length; i++) {
System.out.print(inputArray[i] + " ");
}
System.out.println("\n输出数组为:");
for (int i = 0; i < length; i++) {
System.out.print(outputArray[i] + " ");
}
}
}
```
运行结果示例:
```
请输入数组的长度:5
请逐个输入数组元素:
1
2
3
4
5
输入数组为:
1 2 3 4 5
输出数组为:
1 2 3 4 5
```
阅读全文