试图让我的矩阵打印而不是堆地址 [英] Trying to get my matrix printed not the heap address
问题描述
代码似乎运行,除了我得到的不是指定(由用户)大小的矩阵,但我认为是堆地址
这是当用户为大小输入2时返回的内容然后是4个数字:
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:
输入矩阵大小:
2
逐行输入2 x 2矩阵:2 3 4 5
行排序矩阵是...... [[D @ 3c954549BUILD SUCCESSFUL(总时间:8秒)
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数组不会覆盖 toString()
,因此您将从 Object
获取默认实现。相反,您可以使用 Arrays.deepToString(Object [])
喜欢
Java arrays do not override toString()
so you are getting the default implementation from Object
. Instead, you can use Arrays.deepToString(Object[])
like
System.out.println("The row-sort matrix is..." + Arrays.deepToString(m));
这篇关于试图让我的矩阵打印而不是堆地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!