What is the code in java? Make it super simple to understand. Exercise Generic:
ID: 3720880 • Letter: W
Question
What is the code in java? Make it super simple to understand.
Exercise Generic: Write a generic method that is called printArrayReversed It has one parameter an array of type T- and it returns nothing It prints all the elements of the array separated by a single space (blank) and in reverse order When all elements have been printed the method printArrayReversed advances the cursor to the next line Test the method with at least 2 different arrays and print the results Output: fly dog cat bat uoieaExplanation / Answer
PrintArrayReversedTest.java
public class PrintArrayReversedTest {
public static void main(String[] args) {
Character ch[]= {'a','e','i','o','u'};
String s[]= {"bat","cat","dog","fly"};
printArrayReversed(s);
printArrayReversed(ch);
}
public static <T> void printArrayReversed(T[] a) {
for(int i=a.length-1;i>=0;i--){
System.out.print(a[i]+" ");
}
System.out.println();
}
}
Output:
fly dog cat bat
u o i e a
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.