Question 1 (4 mark) : Implement a program which reads in a series of integers which is input by the user into an array a
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Question 1 (4 mark) : Implement a program which reads in a series of integers which is input by the user into an array a
Question 1 (4 mark) : Implement a program which reads in a series of integers which is input by the user into an array and prints it out in reverse order. REQUIREMENTS • The user input is always correct input verification is not required). • Your code must use recursion and array. • The recursion method void printNumber(int[] array, int index) is a recursion one whose arguments are a positive integer array and one integer. The main method prompts the user to enter the number num of an array first, and then to enter the elements of the array myArray. The recursive method printNumber is then called to display the sequence of numbers in reverse order. • Your code must work exactly like the following example (the text in bold indicates the user input). Example of the program output: Example 1: Enter the length of your array: 6 Enter the elements of your array: 1 2 3 4 5 6 Your array in reverse order is: 6 5 4 3 2 1 Example 2: Enter the length of your array: 5 Enter the elements of your array: 2 5 8 12 67 Your array in reverse order is: 67 12 8 5 2