Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript Java
Could someone let me know why my code will not print an int array, instead it prints a string such as [[I@1d256a73
 
public class ArrayMultiplication {
	public static void main (String args []){
	int [][]a={{1,6,2},{4,18,3},{5,8,4}};
	int [][]b= {{9,12,13},{6,9,7},{32,4,3}};
	int [][]product = multiply (a,b);
	System.out.println (""+product);
	}
	public static int [][] multiply (int [][]a, int[][]b){
		int aRows=a.length;
		int aColumns=a[0].length;
		int bRows=b.length;
		int bColumns=b[0].length;
		if (aRows != aColumns || bRows != bColumns) {
			return null; 
		}
		int[][]resultantProduct = new int [aRows][aColumns];
		for (int i=0; i<aRows; i++) {
			for (int h=0; h<aColumns; h++) {
				resultantProduct [i][h] += a[i][h] * b[i][h];
			}
		}
		return resultantProduct;
	}
}
	
Posted 9-Nov-12 19:20pm
Edited 10-Nov-12 7:11am
v3
Comments
Richard MacCutchan at 10-Nov-12 12:14pm
   
If my suggestions solved the question then please mark it as the solution. But leave the original question intact so other people can read it and benefit from the information.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

	System.out.println (""+product);
product is the name of a two-dimensional array, but the println() function has no way of knowing how to print its contents, so it treats the address as an integer value and prints that. You need to write a loop to print each individual element of the array in whatever form and format you require.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 425
1 OriginalGriff 184
2 BillWoodruff 170
3 Zoltán Zörgő 165
4 Maciej Los 163
0 OriginalGriff 7,854
1 DamithSL 5,949
2 Sergey Alexandrovich Kryukov 5,449
3 Maciej Los 5,084
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 10 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100