fork(1) download
  1. import java.util.Arrays;
  2.  
  3. public class Main {
  4.  
  5. public static void reverse(Object [] a){
  6. for(int i = 0; i < a.length / 2; i++){
  7. Object temp = a[i]; // swap using temporary storage
  8. a[i] = a[a.length - i - 1];
  9. a[a.length - i - 1] = temp;
  10. }
  11. }
  12.  
  13. public static void main(String[] args) {
  14. String [] a = new String[]{"first", "second", "third", "fourth"};
  15. String [] b = new String[]{"first", "second", "third"};
  16.  
  17. reverse(a);
  18. reverse(b);
  19.  
  20. System.out.println(Arrays.toString(a));
  21. System.out.println(Arrays.toString(b));
  22. }
  23. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
[fourth, third, second, first]
[third, second, first]