Modify the above program to complete the same task by replacing the array with ArrayList so...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Modify the above program to complete the same task by replacing the array with ArrayList so that the user does not need to specify the input length at first. The recursion method's first argument should also be changed to ArrayList. The user input ends up with -1 and -1 is not counted as the elements of ArrayList. REQUIREMENTS ● . . ● ● The user input is always correct (input verification is not required). Your code must use recursion and ArrayList. The recursion method int addition (ArrayList<Integer> al, int start Index) is a recursion one whose arguments are an integer ArrayList and an integer, the return value is an integer. The main method prompts the user to enter the elements of the ArrayList myArrayList, calculates the addition of all elements of the array by calling the method addition (myArrayList, 0), displays the result as the following examples. Your code must work exactly like the following example (the text in bold indicates the user input). Example of the program output: Example 1: The elements of your array are: 123456-1 The addition of 1, 2, 3, 4, 5, 6 is 21. Example 2: The elements of your array are: 25 8 12 67 -1 The addition of 2, 5, 8, 12, 67 is 94. Modify the above program to complete the same task by replacing the array with ArrayList so that the user does not need to specify the input length at first. The recursion method's first argument should also be changed to ArrayList. The user input ends up with -1 and -1 is not counted as the elements of ArrayList. REQUIREMENTS ● . . ● ● The user input is always correct (input verification is not required). Your code must use recursion and ArrayList. The recursion method int addition (ArrayList<Integer> al, int start Index) is a recursion one whose arguments are an integer ArrayList and an integer, the return value is an integer. The main method prompts the user to enter the elements of the ArrayList myArrayList, calculates the addition of all elements of the array by calling the method addition (myArrayList, 0), displays the result as the following examples. Your code must work exactly like the following example (the text in bold indicates the user input). Example of the program output: Example 1: The elements of your array are: 123456-1 The addition of 1, 2, 3, 4, 5, 6 is 21. Example 2: The elements of your array are: 25 8 12 67 -1 The addition of 2, 5, 8, 12, 67 is 94.
Expert Answer:
Answer rating: 100% (QA)
Code import javautil class multiply static int multiplicationArrayList al int startIndex i... View the full answer
Related Book For
Advanced Accounting
ISBN: 978-0538480284
11th edition
Authors: Paul M. Fischer, William J. Tayler, Rita H. Cheng
Posted Date:
Students also viewed these accounting questions
-
Question 4 [7 marks] Part a) (3 marks) Calculate the statistic, set up the rejection region, draw the sampling distribution and interpret the result, Ho: H: Given that: -10, n-100, X-10, a-0.05. -10...
-
KPMG, the audit, tax, and advisory firm, has enjoyed high employee morale for the last several years about 80% of its 29,000 professionals say it is a great place to work. But the firm wanted to...
-
Why might a business be willing to consider alternative dispute resolution instead of formal litigation? Question 4 options: It is private, and it can allow involvement of mediators or arbitrators...
-
3. (15 pts.) The random variables X and Y have joint density function fxx(x, y) x-?y?, x > 1, y > 1. Compute the cdf and pdf of the random variable U = XY.
-
Suppose that three fair dice are tossed. Let Ai be the event that a 6 shows on the ith die, i = 1, 2, 3. Does P (A1 A2 A3) = 1 / 2? Explain.
-
Rozema, Inc., produces chemicals for large biotech companies. It has the following data for manufacturing overhead costs during August 2013: Use F for favorable and U forunfavorable: Fixed $18,000...
-
Tick Ltd and Tock Ltd both began operations on 1 January 2025. For illustrative purposes, assume that at that date their statement of financial positions was identical and that their operations...
-
Bank 98 operates a main location and three branch locations in a medium-size city. All four locations perform similar services, and customers typically do business at the location nearest them. The...
-
Manufacturing cost data for Marin Company are presented as follows. Determine the missing amount for each letter (a) through (i). Direct materials used Direct labor Case A (a) 59,900 Case B $72,900...
-
Take-a-Break Travel Company offers spring break travel packages to college students. Two of its packages, a 7-day, 6- night trip to Cancun and a 5-day, 4-night trip to Jamaica, have the following...
-
An insurance company selected a sample of 160 claims from each of its 24 branch offices and examined them for fraud. The number of fraudulent claims at each of the 24 offices are given in the...
-
Given the following, which can fill in the blank and allow the code to compile? (Choose three.) var quest = for (var zelda : quest) { System.out.print(zelda); }
-
Fill in the blank with the line of code that causes the application to compile and print exactly one line at runtime. package nyc; public class TourBus { public static void main(String... args) { var...
-
Which are true statements about referencing variables from a lambda? (Choose two.) A. Instance and static variables can be used regardless of whether effectively final. B. Instance and local...
-
Which of the following rules about a default branch in a switch statement are correct? (Choose two.) A. A switch statement is required to declare a default statement. B. A default statement must be...
-
What is output by the following? A. 3 10 B. 3 12 C. 5 10 D. 5 12 E. The code does not compile. F. None of the above. 10: int m = 0, n = 0; 11: while (m < 5) { 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:...
-
Provide details about following topics from quality management Manufacturing functions and quality, Product and Service quality dimensions, Education and Health Care quality initiatives, Importance...
-
State whether each statement is true or false. If false, give a reason. {purple, green, yellow} = {green, pink, yellow}
-
Pearson and Murphy have partner capital balances, at book value, of $45,000 and $65,000 as of December 31. Pearson is allocated 60% of profits or losses, and Murphy is allocated the balance. The...
-
Based on the following very limited information, indicate whether and how the city should report its related entity. 1. Its school district, although not a legally separate government, is managed by...
-
Tweeden Corporation is contemplating the acquisition of the net assets of Sylvester Corporation in anticipation of expanding its operations. The balance sheet of Sylvester Corporation on December 31,...
-
Using a search engine such as Google, search for power of a hypothesis test. Describe what the power of a hypothesis test is.
-
H 0 : The lottery is fair. Ha: The lottery is biased. Without using the terms null hypothesis and alternative hypothesis, identify the type I error and identify the type II error.
-
What do p, p, and P-value represent?
Study smarter with the SolutionInn App