试图让我的矩阵打印而不是堆地址

时间:2014-11-02 23:13:35

标签: java matrix heap

代码似乎运行,除了我得到的不是指定(由用户)大小的矩阵,但我认为是一个堆地址 以下是用户输入2作为大小然后输入4个数字时返回的内容:

输入矩阵大小: 2 逐行输入2乘2矩阵:2 3 4 5 行排序矩阵是...... [[D @ 3c954549BUILD SUCCESSFUL(总时间:8秒)

这是代码....提前谢谢你。

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);


   }

1 个答案:

答案 0 :(得分:0)

Java数组不会覆盖toString(),因此您将从Object获取默认实现。相反,您可以使用Arrays.deepToString(Object[])之类的

System.out.println("The row-sort matrix is..." + Arrays.deepToString(m));