I have a toString() method that goes through a for loop and is supposed to print each element in the array, but I'm still getting the location when I call the toString() method. How could I fix this?
public void toString(String[] num) {
for (int index = 0; index < num.length; index++) {
System.out.println(num[index]);
}
}
public static void main(String[] args) {
//test negative number, output should be -10000000
int largeNum1[] = {-2, 0, 0, 0, 0, 0, 0, 0};
int largeNum2[] = {1, 0, 0, 0, 0, 0, 0, 0};
int numSize1 = (largeNum1.length + largeNum2.length) + 1;
int[] sum1 = new int[numSize1];
int[] answer1 = sumNumbers(largeNum1, largeNum2, sum1);
System.out.println(largeNum1.toString() + " + " + largeNum2.toString() + " = " + answer1.toString());
}
Instead of -20000000 + 10000000 = -10000000, my output is [I@182decdb + [I@26f0a63f = [I@4361bd48