Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please actually answer it... In this assignment, you are to write a java program that reads an array of integers of a certain size. So,

Please actually answer it...

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. 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: 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 Now the program exits.

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

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

How can the success of a scheduling system be measured?

Answered: 1 week ago

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago