0

Hello fellow Stackoverflowers,

How do I print out the numbersArray so that I can see the numbers?

When I sysout the numbersArray, it shows me:

[I@677327b6

[I@677327b6

Thank you for your time and help!

package AlgoExercises;

public class InsertionSort {

  static int[] numbersArray = { 5, 2, 4, 6, 1, 3 };

  static void swap(int a, int b) {
    int temp = a;
    a = b;
    b = temp;
    // a and b are copies of the original values.
    // The changes we made here won't be visible to the caller.
  }

  static void insertionSort(int[] numbersArray) {
    for (int i = 1; i < numbersArray.length; i++) {
      int j = i;
      while ((j > 0) && (numbersArray[j] < numbersArray[j - 1])) {
        swap(numbersArray[j], numbersArray[j - 1]);
        j = j - 1;
        System.out.println(numbersArray);
      }
    }
  }

  public static void main(String args[]) {
    insertionSort(numbersArray);
  }
}
TaiAu
  • 49
  • 6

2 Answers2

0

For printing out arrays use java.lang.Arrays.toString() method:

System.out.println(Arrays.toString(numbersArray));
Andremoniy
  • 34,031
  • 20
  • 135
  • 241
0

System.out.println(numbersArray); You are printing an array instead of values. you should print the value by numbersArray[i]

Shriram
  • 4,343
  • 8
  • 37
  • 64