-4
我想学习java,当然我是初学者。我面临初始化多维数组时遇到的问题。这里是我想写的代码...多维数组初始化遇到问题
import java.util.Scanner;
public class one {
public static void main(String args[]) {
int p[][] = null;
System.out.println("Type ur array here:");
System.out.println("how many rows and column:");
int row, colmn;
Scanner u = new Scanner(System.in);
Scanner y = new Scanner(System.in);
Scanner t = new Scanner(System.in);
Scanner r = new Scanner(System.in);
row = t.nextInt();
colmn = r.nextInt();
for(int i = 0; i <= row; i++)
for(int v = 0; v <= colmn; v++){
int j = u.nextInt();
p[row][colmn] = j;
}
int a[][] = p;
System.out.println("The given array:");
y(a);
}
public static void y(int n[][]) {
for(int i=0;i<n.length;i++) {
for(int j=0;j<n[i].length;j++){
System.out.print(n[i][j]);
}
System.out.println();
}
}
}
请有人纠正这一点,并为我提供足够的知识,我需要。
可以初始化与'INT多维数组[] [] P =新INT [容量] [captacity]; ' – August
@八卦或者'int [] [] p = new int [capacity] []'而不是。请注意,第二个容量可以留空,在这种情况下,可以用'p [index] = new int [capacity]'自由地建立第二个维数组。 – Unihedron
另外,___请使用描述性变量名称。 – Unihedron