JAVA实现数组内容反转输出
import java.util.Scanner;
public class jiaohuan {
public static void main(String[] args) {
int[] arr = new int[5];
System.out.println(“请为数组赋值”);
Scanner ab = new Scanner(System.in);
for (int i = 0; i < arr.length; i++) {
arr[i] = ab.nextInt();
}
int temp;
int ag = 0;
for (int end = arr.length - 1;
ag < end;
end–, ag++){ temp=arr[ag];
arr[ag]=arr[end];
arr[end]=temp;
}
for (int i = 0; i <arr.length ; i++) {
System.out.println(“数组交换后为”+arr[i]);
}
}
}
2021-01-25
最新推荐文章于 2021-10-25 02:08:04 发布