fork download
  1. import java.util.*;
  2.  
  3. public class Main {
  4.  
  5. /*function reverses the elements of the array*/
  6. static void reverse(Integer myArray[])
  7. {
  8. Collections.reverse(Arrays.asList(myArray));
  9. System.out.println("Reversed Array:" + Arrays.toString(myArray));
  10. }
  11.  
  12. public static void main(String[] args)
  13. {
  14. Integer [] myArray = {1,3,5,7,9};
  15. System.out.println("Original Array:" + Arrays.asList(myArray));
  16. reverse(myArray);
  17. }
  18. }
Success #stdin #stdout 0.12s 50304KB
stdin
Standard input is empty
stdout
Original Array:[1, 3, 5, 7, 9]
Reversed Array:[9, 7, 5, 3, 1]