Double the size of a 1-D Array. Once an array is created, its size is fixed....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Double the size of a 1-D Array. Once an array is created, its size is fixed. Occasionally, you need to add more values to an array, but it is full. In such a case, you can create a new larger array to replace the existing array. Write a method with the following header: public static int [] double Capacity (int[] list) The method returns an array variable referencing to a new array that doubles the size of the input array referenced by the parameter list. The contents of the first half of the new array should be the same as the input array; use 0 as the value for the elements in the second half of the new array. For example, if the input array is {1, 2, 3, 4, 5}, the new array should be {1, 2, 3, 4, 5, 0, 0, 0, 0, 0}. Put the doubleCapacity method and the main method in one class. The purpose of the main method is to test your doubleCapacity method. Design your own main method-the minimal requirements are: 1. Create an input array of your choice. 2. Display the contents of the array from Step1 using a displayArray method. 3. Invoke the doubleCapacity method to create a new double-sized array. 4. Display the contents of the new array created in Step2 using the displayArray method again. The diplayArray method should have the following header: public static void displayArray (int () list) Note: Your output should look exactly like the output below and should be able to run test cases. Please enter the array size: 5 Please enter your array of size 5: 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 0 0 0 0 0 Double the size of a 1-D Array. Once an array is created, its size is fixed. Occasionally, you need to add more values to an array, but it is full. In such a case, you can create a new larger array to replace the existing array. Write a method with the following header: public static int [] double Capacity (int[] list) The method returns an array variable referencing to a new array that doubles the size of the input array referenced by the parameter list. The contents of the first half of the new array should be the same as the input array; use 0 as the value for the elements in the second half of the new array. For example, if the input array is {1, 2, 3, 4, 5}, the new array should be {1, 2, 3, 4, 5, 0, 0, 0, 0, 0}. Put the doubleCapacity method and the main method in one class. The purpose of the main method is to test your doubleCapacity method. Design your own main method-the minimal requirements are: 1. Create an input array of your choice. 2. Display the contents of the array from Step1 using a displayArray method. 3. Invoke the doubleCapacity method to create a new double-sized array. 4. Display the contents of the new array created in Step2 using the displayArray method again. The diplayArray method should have the following header: public static void displayArray (int () list) Note: Your output should look exactly like the output below and should be able to run test cases. Please enter the array size: 5 Please enter your array of size 5: 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 0 0 0 0 0
Expert Answer:
Related Book For
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba
Posted Date:
Students also viewed these programming questions
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
In a small country near the Baltic Sea, there are only three commodities: potatoes, meatballs, and jam. Prices have been remarkably stable for the last 50 years or so. Potatoes cost 2 crowns per sack...
-
Predict the ordering of the C-O bond lengths in CO, CO2, and CO32-.
-
A seller has offered credit terms of 2.5/5 net 50 to a customer that has agreed to immediately purchase 500 units at a sales price per unit of $100. Variable costs are $65 per unit and involve an...
-
Ki Corp. is in liquidation under Chapter 7 of the Federal Bankruptcy Code. The bankruptcy trustee has established a new set of books for the bankruptcy estate. After assuming custody of the estate,...
-
Three tests have been used by various courts in common-law decisions to determine which third-party users can successfully bring a suit against the auditor for negligence. Identify each of these...
-
Leveraged Investing with Eligible Dividends $50,000 Cash purchase + $50,000 borrowed funds at 4.95% 12 month holding period Eligible monthly dividend of $0.07/share Purchase price of $25.00 Sale...
-
If a firm borrows $500,000 at 10% and is required to maintain $50,000 as a minimum compensating balance at the bank, what is the effective interest rate on the loan? 10.0% 11.1% 9.1% 12.2%
-
A monopsony is ___________. a) the only seller of a product for which there are no close substitutes b) the only buyer of a product for which there are no close substitutes c) both the seller and the...
-
A firm will use increasing amounts of a resource until the ____________ of that resource is equal to its ________________ .
-
Which is the most accurate statement about the recent wave of corporate corruption? a) It has hurt employees, stockholders, and, in general, the entire economy. b) It has actually been very healthy...
-
Right-to-work laws promote the formation of _________. a) closed shops b) union shops c) open shops
-
Which statement is true? a) No union is a monopoly. b) Some unions are monopolies. c) All unions are monopolies.
-
Identify a system-of-systems whose analysis could yield insights not available by separately analyzing the individual systems of which it is composed.
-
In Exercises evaluate the limit, using LHpitals Rule if necessary. lim 07x cos x X
-
Calculate the volatility and the current price of oil futures implied by the call 1600 August and the call 1700 August of Figure 19.8 by using the Black-Scholes formula with \(T=.25\). OIL CRUDE OIL...
-
A company issues a \(10 \%\) coupon bond that matures in 5 years. However, this company is in trouble, and it is estimated that each year there is a probability of .1 that it will default that year....
-
Consider a continuous-time environment, with \(e\) as a variable outside of the market. (a) Suppose the final payoff is \(V\left(x_{e}, T ight)=x_{e}(T)\). Find \(V\left(x_{e}, t ight)\). (b) Find a...
Study smarter with the SolutionInn App