MysteryArray.java


Below is the syntax highlighted version of MysteryArray.java.


public class MysteryArray {
   public static void main(String[] args) {
      int N = args.length;
      int[] a = new int[N];
    
      // store the arguments in an integer array
      for (int i = 0; i < N; i++) {
          a[i] = Integer.parseInt(args[i]);
      }
    
      // What is happening here?
      for (int i = 0; i < N/2; i++) {
          int temp = a[i];
          a[i] = a[N - i - 1];
          a[N - i - 1] = temp;
      }
    
      // print out the elements
      for (int i = 0; i < N; i++) {
          System.out.print(a[i] + " ");
      }
      System.out.println();
   }
}