-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