The code seems to run except what I am getting is not a matrix of a specified (by the user) size but what I think is a heap address Here's what it returns when the user inputs 2 for the size and then 4 numbers:
Enter matrix size: 2 Enter a 2 by 2 matrix row by row: 2 3 4 5 The row-sort matrix is...[[D@3c954549BUILD SUCCESSFUL (total time: 8 seconds)
here is the code....thank you in advance.
import java.util.Scanner;
public class Exercise7_26M {
public static void main (String[]args)
{
//Prompt user for input of matrix size
System.out.println("Enter matrix size: ");
Scanner input = new Scanner(System.in);
int size = input.nextInt();
double[][] m = new double [size][size];
//prompt user for input of array
System.out.print("Enter a " + size + " by " + size + " matrix row by row: ");
for (int row = 0; row < 2; row++)
for (int column = 0; column < 2; column++)
m[row][column] = input.nextDouble();
System.out.print("The row-sort matrix is..." + m);
}
Java arrays do not override
toString()
so you are getting the default implementation fromObject
. Instead, you can useArrays.deepToString(Object[])
like