Question: n this assignment, you are to write a java program that reads an array of integers of a certain size. So , first it will

n this assignment, you are to write a java program that reads an array of integers of a certain
size. So, first it will ask the user to input the size of the array (lets call this size), then it
proceeds to read the elements of the array (array). Do not assume a maximum number of
elements in the array. You should input the numbers in the array in sorted order all the time. If
the user inputs the number in a non-sorted order, then the program should print an error
message an exit. Therefore, you are required to check to see if the array is sorted (you need to
implement a recursive function that checks to see if the array is sorted).
Once the array is read in and verified as sorted, the user should be asked to input a single
integer (lets call this one S). Then you are required to write a recursive function that checks to
see if the array contains two numbers that add up to the number S or not. If so, then your
program should print a message indicating that yes the array does have two numbers that add
up to S, otherwise, the program should print a message indicating no it doesnt.
Your program should continue to perform the above tasks until a user inputs in an array of size
0, then the program should stop.
The requirements:
You only need one .java program
You must have two recursive functions in addition to main:
o One to take the array as an argument and check if its sorted.
o Another to take an array and an integer as arguments and returns if the array has two
numbers that add up to the integer.
Your program must run indefinitely until a 0 is entered for the size to allow you to test
with various test cases.
Make sure that your program is well documented (commented very well), and is as
user-friendly as possible.
You must submit your source code only (the .java file)
The following scenario should help you design your program:
Please Enter a Size or Zero to stop: 5
Please Enter an array of 5 elements: 3891014
Please Enter a single Integer: 18
Answer: Yes the array contains two numbers that add up to 18.
----
Please Enter a Size or Zero to stop: 6
Please Enter an array of 5 elements: 38910147
***** Error the array must be sorted. ----
Please Enter a Size or Zero to stop: 6
Please Enter an array of 5 elements: 389101418 Please Enter a single Integer: 25
Answer: No the array does not contain two numbers that add up to 25.
---
Please Enter a Size or Zero to stop: 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!