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% (QA)
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.
-
A reliable sales forecast has been obtained indicating that the Special Products Company (see Section 1.2) would be able to sell 30,000 iWatches, which appears to be enough to justify introducing...
-
What would happen to the SML graph in Figure 8.8 if expected inflation increased or decreased? Figure 8.8 268 269 270 271 272 273 274 275 A Required Rate of Return TH-13.0% SML: r, RF+RPM * b D E F H...
-
In 2008, Van Hover Inc. adopted the dollar-value LIFO retail inventory method. The January 1, 2008, price index was 1.00. The following data are available for the 4-year period ending December 31,...
-
Westeros, Inc. receives scabbards (sheath for a sword) from two different suppliers. 70 percent of its scabbards come from Knights Watch, LLC, while 30 percent come from Crow, Inc. Records indicate...
-
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();
-
Bobs Pharmacy has several Medicaid patients. One of the physicians tends to write his Medicaid prescriptions for brand name drugs, even though generic drugs are available. When Bob calls the...
-
For the following three vectors, what is 2 (2 B) ? . = 4.00i + 3.00 j 2.00k 4.00 +3.00 = 8.00 -8.007 Number Jaka +2.00k Units
-
3- Consider the block diagram in Figure 2, Ye(t) L(s) F(s) K(s) a. Derive the following transfer functions, S(s) = Y.(s) T(s) = Y(s) = Y(8) E(s) 0 + Figure 2 u(t) SHLA Y(8) Hby (8) = B(s) Hnu(s):...
-
3. Kye Inc. has listed the price for two potential suppliers as shown in Table 2. Kye uses 700 units of wheel per month, estimate holding cost to be 30% of the purchase price, estimate order cost to...
-
2 There are two jack screw assemblies both with an ISO Metric Trapezoidal 'Tr 16 x 3' screw, one single-thread and the other double-thread. Each assembly raises and then lowers a load of 450 kg. A...
-
You push a box along the floor such that it moves at constant veloeity. Which of the fallen describes the Newton's 3 rd law ( N 3 L ) pairing force to this applied force on the bort The gravitational...
-
List all the accounts that can be affected by the plug value. How does this value help managers?
-
Perform the indicated operations. In designing a cam for a fire engine pump, the expression is used. Simplify this expression. (3) (3 4 32
-
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?
-
5. One efficient way to express the concentration of a solution for many chemistry applications is molarity. Molarity (M) is defined as the number of moles of solute in 1 liter (1 L) of the solution:...
-
When a 28.8 mL sample of a 0.450 M aqueous hydrocyanic acid solution is titrated with a 0.352 M aqueous barium hydroxide solution, (1) What is the pH at the midpoint in the titration? 9.3 (2) What is...
-
The Global Treps Project team is working hard to ensure they meet expectations, especially for the people who will be holding and participating in events. The team has a detailed scope statement, but...
Study smarter with the SolutionInn App