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.
-
Geoff and Sandy Harland own and operate Wayward Kennel and Pet Supply. Their motto is, "If your pet is not becoming to you, he should be coming to us." The Harlands maintain a sales tax payable...
-
Air enters a length of constant area pipe with \(p_{1}=200\) \(\mathrm{kPa}(\mathrm{abs}), T_{1}=500 \mathrm{~K}\), and \(V_{1}=400 \mathrm{~m} / \mathrm{s}\). If \(500 \mathrm{~kJ} / \mathrm{kg}\)...
-
Miriam is a self-employed computer consultant. Her business nets $120,000 annually and she takes $85,000 of the earnings in salary. Miriam is considering incorporating her computer consulting...
-
For the following scenario, I need you to answer the following questions to. Be sure to cite the authority that supports your analysis for each question. Also, cite 2 scriptures in the Bible that...
-
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();
-
In a survey of 500 randomly selected high school teachers and 1000 randomly selected grade school teachers, 160 (32%) of the high school teachers and 260 (26%) of the grade school teachers cited lack...
-
The quantity of energy Q transferred by heat conduction through an insulating pad in time interval At is described by Q/At= KAAT/d, where K is the thermal conductivity of the material, A is the face...
-
Nowadays when people use electronic devices such as iPhone, many of them just accept the default setting and do not want to research the full features of using these devices. This is an example of _...
-
Shown at right is the first section of a rollercoaster. a ) Calculate gravitational potential energy of 1 0 0 kg cart at position A . b ) How fast would the car be traveling at B , ( no friction...
-
What is the difference between strategic planning and a business plan? explain and give examples
-
4. You are standing on the surface of the an unknown planet with no at- mosphere. In order to test the acceleration due to gravity, you throw a ball at a speed of 10 m/s at an angle of 25 above the...
-
Return to problem. Using OM Explorer, how long do you estimate the time required to install the fifth pool? A contractor is preparing a bid to install swimming pools at a new housing addition. The...
-
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?
-
Adam Barone stated that a marketing strategy refers to a business's overall game plan for reaching prospective consumers and turning them into customers of their products or services. A marketing...
-
The balance sheet for Pina Colada Consulting reports the following information on July 1, 2022. Long-term liabilities Bonds payable $1,280,000 Less: Discount on bonds payable 51,200 $1,228,800 Pina...
-
Give your short opinion on each paragraph below and reply with reference. 1.McDermott's background, which includes experiences such as managing a deli shop in Long Island and working in sales for...
Study smarter with the SolutionInn App