I am trying to print out the return of my method but i keep getting something different. The problem states:
Implement a method named totals that takes a two dimensional integer array named array as a parameter
and returns a one dimensional array where each element is the sum of the columns of the input array.
the method that i wrote is:
Code:
public class ArrayMethods2 {
public int[] totals (int[][] array){
int[] sumCol = new int[array[0].length];
for(int row = 0; row < array.length; row++){
for(int col = 0; col < array[row].length; col++){
sumCol[col] += array[row][col];
}
}
return sumCol;
}
and my main method to run it i have:
Code:
import java.util.Scanner;
public class RunArray2{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayMethods2 am2 = new ArrayMethods2();
System.out.println("\nMethod \"totals"+ "\"");
System.out.println("Enter dimension of two dimensonal array");
System.out.print("row size: ");
int row = scan.nextInt();
System.out.print("col size: ");
int col = scan.nextInt();
int[][] twoDArray = new int[row][col];
for(int i=0; i < twoDArray.length; i++){
for(int j=0; j < twoDArray[i].length; j++){
twoDArray[i][j] = scan.nextInt();
}
}
System.out.println("The array entered is: ");
for(int i=0; i < twoDArray.length; i++){
for(int j=0; j < twoDArray[i].length; j++)
System.out.print(twoDArray[i][j] + " ");
System.out.println();
}
System.out.println("Sum of the columns: ");
System.out.println(am2.totals(twoDArray));
}
}
my output is this:
Code:
Method "totals"
Enter dimension of two dimensonal array
row size: 3
col size: 3
1 2 3
4 5 6
7 8 9
The array entered is:
1 2 3
4 5 6
7 8 9
Sum of the columns:
[I@3d4eac69
trying to figure out why i am getting that for the sum of my columns. any suggestions?