m trying to write a program that will read a list of integers and output the integers in reverse. the first number is supposed to tell the program the number of elements. that go into the array import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int[] userList = new int[20]; int numElements; numElements = scnr.nextInt(); the next for loop is intended to add the proper number of elements to the array. for (int i = 0; i < numElements.lengt
im trying to write a
the first number is supposed to tell the program the number of elements. that go into the array
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int[] userList = new int[20];
int numElements;
numElements = scnr.nextInt();
the next for loop is intended to add the proper number of elements to the array.
for (int i = 0; i < numElements.length; ++i) {
numElements(i) = scnr.nextInt();
System.out.println(numElements(i));
}
but i keep getting errors,
I also want to put in another for loop to loop it backwards and print the numbers in the array list backwards but im a little unsure how to do that. could you walk me through this?

The correct steps to create the program are listed below.
- Read the size of array
- Create an array with the input size to store the elements.
- Read the elements using a for loop from i=0 to one less than the size of the array.
- Use a for loop from i=size-1 to 0 to print the elements of the array in reverse order by using i as the index.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 2 images









