Arraying 102
by CodeChum Admin
We've already made arraying/listing the easy way, but how about arraying/listing and printing the list in reverse order?
Make a program that will input an integer and then using loops, add items on an array/list one by one for the same number of times as that of the first inputted integer. Then, print out the array/list in reverse order, that is, starting from the last item on the array/list down to the first one, each in separated lines.
Input
The first line contains the size of the array/list.
The next lines contains the items of the array/list (integers).
5
1
64
32
2
11
Output
Multiple lines containing integers.
11
2
32
64
1
import java.util.Scanner;
public class App {
/**
* The start point of the program
*
* @param args
*/
public static void main(String[] args) {
Scanner keyBoard = new Scanner(System.in);
int n = keyBoard.nextInt();
int integers[] = new int[n];
for (int i = 0; i < n; i++) {
integers[i] = keyBoard.nextInt();
}
for (int i = n - 1; i >= 0; i--) {
System.out.println(integers[i]);
}
keyBoard.close();
}
}
Comments
Leave a comment