Question: Please use Java Problem 4. Maximum Subarray (MaxSubSum.java) Description Given an integer array nums, find the contiguous subarray (containing at least one number) that has
Problem 4. Maximum Subarray (MaxSubSum.java) Description Given an integer array nums, find the contiguous subarray (containing at least one number) that has the largest sum and return its sum. Write a Java class named MaxSubSum to fulfill the above task. This class will have the following methods: 1) getData(): has not parameter, but will return an integer array of Nintegers. N is a number determined by user's input. Ask the user to enter these N arbitrary Integers. 2) getMaxSubSum(): has one parameter which is an integer array. Return the maximum sum of sub array of this array. 3) main() method: Call the getData() to get the integer array. Call the getMaxSubSum) and return the maximum sum of the sub arrays Outputs: Sjava MaxSubSum How many integers do you want to enter:29 Please enter 9 integers: -2134-121.54 The maximum subarray sum is: 10 Explanation: (4.-1. 2. 1) has the largest sum = 10 Problem 5. The most frequent element (MostFrequentjava) Description: Write a Java class named Most Frequent that will read in an array from command line arguments, find the element that appears most frequently in the array and print that element out You may assume that the array is non-empty, and that you can break the tie by choosing the lower value. For example, if an array contains value (27,15,15,11,27), the most frequent one with lower value would be 15. This fava class is expected to include the following two methods: .getMostFrequent(): has one parameter which is an integer array. Return the most frequent element in this array. .main(): create an integer array from command-line arguments. Call the getMost Frequent() method, and display the result. Outputs: Sjava Most Frequent 22321002 The element appears most frequently is: 2 Sjava Most Frequent 1 The element appears most frequently is 1 Sjava MostFrequent 7557 The element appears most frequently is: 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
