1 数组的逆序输出1
import java.util.Scanner;
public class P1427 {
public static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
int [] arr = new int [100];
System.out.println("请输入多个正整数(输入-1结束):");
int i=0;
do{
arr[i] = input.nextInt();
i++;
}while(arr[i-1] != -1);
System.out.println("你输入的数组是:");
for(int j2 = 0;j2 < i-1;j2++){
System.out.println(arr[j2]+" ");
}
System.out.println("你输入的数组逆序输出为:");
for(int j2=0;j2<i-1;j2++){
System.out.println(arr[i-2-j2] + " ");
}
}
}
2 数组你逆序输出2
public class P1427 {
public static void main(String[]args){
int a[] = {1, 2, 3, 4, 5};
for(int i = 0; i<a.length; i++){
//顺序输出
System.out.print(a[i] + " ");
}
System.out.print("\n");
int n = a.length;
for(int i = 0; i < n/2; i++){
int temp = a[i];
a[i] = a[n-i-1];
a[n-i-1] = temp;
}
for(int i = 0; i<a.length; i++){
System.out.print(a[i] + " ");
}
}
}