Write a generic method reverseArray that reverses the order of elements in an array. Use this generic
Question:
Write a generic method reverseArray that reverses the order of elements in an array. Use this generic method in a program to reverse arrays of different types.
Print each array both before and after calling reverseArray using a generic method similar to Fig. 20.3.
Fig. 20.3
Transcribed Image Text:
1 // Fig. 20.3: Generic MethodTest.java 2 // Printing array elements using generic method printArray. 1234 3 4 public class GenericMethodTest { 5 6 7 8 9 10 [I 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 } public static void main(String[] args) { // create arrays of Integer, Double and Character Integer [] integerArray = {1, 2, 3, 4, 5); Double[] doubleArray = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7}; Character [] characterArray = {'H', 'E', 'L', 'L', '0'}; System.out.printf("Array integerArray contains: "); printArray(integerArray); // pass an Integer array System.out.printf("Array doubleArray contains: "); printArray (doubleArray); // pass a Double array System.out.printf("Array characterArray contains: "); printArray (characterArray); // pass a Character array } // generic method printArray public static void printArray(T[] inputArray) { // display array elements for (T element : inputArray) { System.out.printf("%s ", element); } } System.out.println(); Array integerArray contains : 1 2 3 4 5 Array doubleArray contains: 1.1 2.2 3.3 4.4 5.5 6.6 7.7 Array characterArray contains: HELL0
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (2 reviews)
To address the question we will create a generic method reverseArray that reverses any type of array ...View the full answer
Answered By
Ajeet Singh
Professional, Experienced, and Expert tutor who will provide speedy and to-the-point solutions.
I have been teaching students for 5 years now in different subjects and it's truly been one of the most rewarding experiences of my life.
I have also done one-to-one tutoring with 100+ students and help them achieve great subject knowledge.
I have expertise in computer subjects like C++, C, Java, and Python programming and other computer Science related fields.
Many of my student's parents message me that your lessons improved their children's grades and this is the best only thing you want as a teacher. I have done plenty of studying and lots of learning on many exciting and challenging topics. All these experiences have influenced my decision to take on the teaching role in various capacities. As a tutor, I am looking forward to getting to understand your needs and helping you achieve your academic goals. I'm highly flexible and contactable. I am available to work on short notice since I only prefer to work with very small and select groups of students.
4.90+
7+ Reviews
15+ Question Solved
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Question Posted:
Students also viewed these Computer science questions
-
Which inequality has as its graph a dashed boundary line and shading below the line? A. y 4x + 3 B. y > 4x + 3 C. y 4x + 3 D. y < 4x + 3
-
Soft pretzels. Build a spreadsheet model that contains the following information. Market size 100,000 units Normally distributed with a standard deviation of 10,000 units 22% Market share Triangular...
-
Write a Java program that calculates and prints the sum of all elements in an integer array. Create a program that finds and prints the maximum value in an array of integers. Write a program that...
-
A soil has a bulk density of 135 lb/ft 3 and a dry density of 120 lb/ft 3 , and the specific gravity of the soil particles is 2.75. Determine (a) moisture content, (b) degree of saturation, (c) void...
-
What are closing entries and why are they necessary? Discuss.
-
The auditor for a large corporation routinely monitors cash disbursements. As part of this process, the auditor examines check request forms to determine whether they have been properly approved....
-
Explain and prepare a classified balance sheet
-
Summit Company makes two models of snowboards, the Junior and the Expert. Its basic production information follows: Summit has monthly overhead of $484,746, which is divided into the following cost...
-
Question 1 (10 marks) Bedok Engineering Pte Ltd manufactures and sells water filters for domestic household use. Price and cost data are as follows: $25.00 Selling price per filter Variable costs per...
-
Overload generic method printArray of Fig. 20.3 so that it takes two additional integer arguments, lowSubscript and highSubscript. A call to this method prints only the designated portion of the...
-
Assuming GClass is a generic class, what is wrong with the following statement: GClass obj = new GClass();
-
The statement Car car; allocates space in memory for an object. (T / F)
-
3. (30 pts total) Suppose that an automobile has the ability to accelerate from rest to a velocity of 100.0 mi/h in a time of 6.00 s. a. (15 pts) Assuming the acceleration is a constant, determine...
-
Factor completely. 2-2t+16
-
Use the following table to answer questions and ll]. The number of hot dogs sold by 12 randomly selected hot dogs vendors in Central Park on July 4 is as follows: 142 97 105 76 90 83 123 115 92 94 73...
-
Can you please describe (in about a paragraph) a situation (preferably but not necessarily in business) that requires a decision necessitating a decision tree with at least two branches, each branch...
-
Data: Sodium Systolic98 14799 14996 175109 14591 135107 14987 121110 170102 163103 141117 14992 13590 12793 132113 18199 152114 164103 14496 148111 180128 18392 13284 135102 141103 147117 16789...
-
A graph of y = f(x) follows. No formula for f is given. In Exercises graph the given equation. (a) G(x) = - 2f(x) (b) g(x) = 1/2 f(x) (c) g(x) = f(- 1/2 x) 4 (2,3) (4, 0) (5, 0) 4x (-1, -2)-
-
A crop-dusting plane flies over a level field at a height of 25 ft. If the dust leaves the plane through a 30 angle and hits the ground after the plane travels 75 ft, how wide a strip is dusted? See...
-
In the analog hierarchy of Figure 6.9, find the overhead (extra bandwidth for guard band or control) in each hierarchy level (group, supergroup, master group, and jumbo group). Figure 6.9 48 kHz 12...
-
Which of the three multiplexing techniques is (are) used to combine analog signals? Which of the three multiplexing techniques is (are) used to combine digital signals?
-
We need to transmit 100 digitized voice channels using a passband channel of 20 KHz. What should be the ratio of bits/Hz if we use no guard band?
-
Long-term liabilities are shown in two places in the business firm's balance sheet depending upon when the long-term liabilities are scheduled for payment. True False
-
Julio is single with 1 withholding allowance. He earned $1,025.00 during the most recent semimonthly pay period. He needs to decide between contributing 3% and $30 to his 401(k) plan. If he chooses...
-
Acquirer firm plans to launch a takeover of Target firm. The manager of Acquirer indicates that the deal will increase the free cash flow of the combined business by $13.6m per year forever. The beta...
Study smarter with the SolutionInn App