31 将一个数组逆序输出

题目:将一个数组逆序输出

 1    public class _031PrintinvertedSequence {
 2 
 3     public static void main(String[] args) {
 4         printinvertedSequence();
 5     }
 6 
 7     private static void printinvertedSequence() {
 8         Scanner scanner = new Scanner(System.in);
 9         int a[] = new int[20];
10 
11         System.out.println("请输入多个正整数(输入-1表示结束):");
12 
13         int i = 0, j;
14 
15         do {
16             a[i] = scanner.nextInt();
17             i++;
18         } while (a[i - 1] != -1);
19 
20         System.out.println("你输入的数组为:");
21         for (j = 0; j < i - 1; j++) {
22             System.out.print(a[j] + " ");
23         }
24         
25         System.out.println("
数组逆序输出为:");
26         for (j = i - 2; j >= 0; j = j - 1) {
27             System.out.print(a[j] + " ");
28         }
29     }
30 }
原文地址:https://www.cnblogs.com/liuyangfirst/p/6537962.html