-1
public class ArrayMethods {
    double[] array = new double[5];

    //swap the first and last elements in the array
    public void swap () {
       array[0]=array[4];
       array[4]=array[0];
       System.out.print(array);
    }
}

Here is my code so far. And this is what it is spiting out with of course random numbers

Original: [D@15db9742

[D@15db9742

but I want it to spit out

Original: 159742

259741

Markus Steppberger
  • 618
  • 1
  • 8
  • 18

1 Answers1

1

You need to buffer one value and print it correctly:

public class ArrayMethods {
        double[] array = new double[5];

        //swap the first and last elements in the array
        public void swap () {
           double temp = array[0];
           array[0]=array[4];
           array[4]=temp;
           System.out.println(Arrays.toString(array));
        }
    }
Markus Steppberger
  • 618
  • 1
  • 8
  • 18