Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

In this assignment, you are to write a java program that reads an array of integers of a certain size. So, first it will as 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.

Requirements:

- You only need one .java program

- You must have two recursive functions in addition to main:

1. One to take the array as an argument and check if its sorted.

2. 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

Output:

Please Enter a Size or Zero to stop: 5

Please Enter an array of 5 elements: 3 8 9 10 14

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: 3 8 9 10 14 7

***** Error the array must be sorted.

----

Please Enter a Size or Zero to stop: 6

Please Enter an array of 5 elements: 3 8 9 10 14 18

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

Good bye

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

More Books

Students also viewed these Databases questions

Question

6. Discuss the steps involved in conducting a task analysis.

Answered: 1 week ago

Question

8. Explain competency models and the process used to develop them.

Answered: 1 week ago