Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment you are to write a Java program that utilizes recursion. Your program should read in an array of integers of any size

In this assignment you are to write a Java program that utilizes recursion. Your program should read in an array of integers of any size (So specify the size first). This is the ONLY time that you are allowed to use a loop of any kind in your program. Once the array is read your program should use a method implemented by you to determine if the sum of the first half of the array is equal to the sum of the second half. This method should be implemented recursively. If the sums are equal, then print the sum of only half the array to the screen. For that you need to implement a method to calculate the sum of half the array, this method also Needs to be recursive. After printing the sum you are to determine if the first half of the array contains the same exact numbers (assume numbers are unique within a half) that are in the second half of the array. Once again this method is also recursive. If the same numbers in the upper half of the array exist in the lower half of the array then you need to determine if the upper two halves are mirror images of each other. If so then print a message indicating that. This will also be another recursive method that you have to write. Therefore, this assignment requires you to write 4 recursive methods to be called from within the main method and from within other recursive methods. Examples for program execution: Example 1 Enter the number of items to read: 12 Enter the number: 1 4 2 5 6 9 8 7 3 4 0 5 Output: Each half of the array sums to 27. The two halves do not contain the same numbers. Example 2 Enter the number of items to read: 12 Enter the numbers: 1 4 2 5 6 9 1 2 5 6 9 4 Output: Each half of the array sums to 27. The two halves contain the same numbers The two halves are not mirror images of each other. Example 3 Enter the number of items to read: 12 Enter the numbers: 1 4 2 5 6 9 9 6 5 2 4 1 Output: Each half of the array sums to 27. The two halves contain the same numbers The two halves are mirror images of each other. Example 1 Enter the number of items to read: 12 Enter the number: 1 4 2 5 6 9 2 4 0 1 8 Output: The two halves have different sums.

a

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 Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions