Question: Objective: Edit the ReverseNumbers Java class to take a list of integers as input, then output that list in reverse. The first line of input
Objective: Edit the ReverseNumbers Java class to take a list of integers as input, then output that list in reverse. The first line of input will be the number of intigers in the list, followed by those intigers.
Example:
If input for the number of intigers is 7, follwed by seven intigers:
7 1000 99 82 61 30 29 2
Then output will be:
2,29,30,61,82,99,1000,
To achieve the above, first read the integers into an array. Then output the array in reverse.
- There are many files in this repository and we will go through what each of them does in class, but the only one you need to edit is ReverseNumbers.java.
- Each time you save your code in this repository a series of tests will be run against your code in a container. To see if your code passed all the tests and is ready to submit, go to the 'Actions' tab of your repository and see if the last commit passed all the tests. If it did, there will be a green checkmark by the last commit, otherwise there will be a red x.
- If you're not sure why your commit didn't pass the tests, click into the commit in the actions tab and then click 'autograding'. You will be able to see the output of the test and use this to determine what went wrong. If you need help, post on Slack!
TO BE WRITTEN IN JAVA
START BY USING THIS CODE
import java.util.Scanner;
public class ReverseNumbers { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int[] userList = new int[20]; // List of numElement integers specified by the user int numElements; // Number of integers in user's list // Add more variables as needed
numElements = scnr.nextInt(); // Input begins with number of integers that follow /* Type your code here. */ } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
