package practice;
import java.util.Scanner;
public class InvertedOutput {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int order[] = new int[10];
for (int i = 0; i < order.length; i++) {
System.out.print("请输入第" + (i + 1) + "个整数:");
order[i] = sc.nextInt();
}
System.out.println("原数组:");
for (int i = 0; i < order.length; i++) {
System.out.print(order[i] + " ");
}
for (int i = 0; i < order.length / 2; i++) {
int temp = order[i];
order[i] = order[order.length - 1 - i];
order[order.length - 1 - i] = temp;
}
System.out.println("\n\n元素两两交换:");
for (int i = 0; i < order.length; i++) {
System.out.print(order[i] + " ");
}
sc.close();
}
}
Java数组元素两两倒置输出
最新推荐文章于 2024-02-25 23:14:50 发布