public class Lab12 {
  /* =array v with its elements in reversed order. 
   * Reverse the array IN PLACE.  Hint: swapping may be useful. 
   */
  public static double[] reverse(double[] v) {
    for (int i=0, j=v.length-1; i<j; i++, j--) {
      double tmp= v[i];
      v[i]= v[j];
      v[j]= tmp;
    }
    return v;
    //Note that the method really doesn't need to return the array
    //since the array was reversed in place.  This is just an
    //exercise on having an array as the return type.
    //Try changing the return type to void (and change the code
    //correspondingly) and check out its use again.
  }
  
  /* Print array values as a column */
  public static void showArray(double[] v) {
    for (int k=0; k<v.length; k++)
      System.out.println(v[k]);
    System.out.println();
  }
  
  public static void main(String[] args) {
    //create a random array
    int aLength= 10;
    double[] a= new double[aLength]; 
    for (int k=0; k<aLength; k++)
      a[k]= Math.random();
    
    showArray(a);
    a= reverse(a);
    showArray(a);
  }
  
  
}