第 10 行出现错误,说明有关 long 的内容。但我不明白为什么会出现这样的错误,因为 int 也可以作为参数。另外,如果是重复的问题,请发送原始问题的链接。
import java.util.Arrays;
import java.util.Scanner;
public class Matrix {
public static void main(String[] args) {
int[][] matrix = Matrix.matrixCreator();
for(int p = 0; p < matrix.length; p++) {
for(int o = 0; o < matrix[p].length; o++) {
System.out.println(Arrays.toString(matrix[p][o]));
}
}
}
public static int[][] matrixCreator() {
int[][] matrix = new int[3][3];
Scanner scan = new Scanner(System.in);
int[] convertToInt = new int[3];
for(int position = 1; position <= matrix.length; position++) {
System.out.printf("Enter the elements of the matrix in row %d separating them with spaces: " , position);
convertToInt[0] = scan.nextInt();
convertToInt[1] = scan.nextInt();
convertToInt[2] = scan.nextInt();
matrix[position - 1] = convertToInt;
}
return matrix;
}
}
它显示的错误是
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method toString(long[]) in the type Arrays is not applicable for the arguments (ints)
at Matrix.main(Matrix.java:10)