-2
我在Java的新嘗試去了解它是如何工作的二維數組,我遇到這個錯誤回報。由於如何擺脫ArrayIndexOutOfBoundsException異常的:3
公共類主要{
public static int n, m, a[][];
public static void main(String []args){
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
m=sc.nextInt();
a=new int[n][m];
int i,j,s=0;
for (i=0;i<n;i++)
for (j=0;j<m;j++){
a[i][j]=sc.nextInt();
}
for (i=0;i<a.length;i++){
for (j=0;j<a[i].length;j++){
if (a[i][j+1]>a[i+1][j]) s=s+a[i][j+1];
else s=s+a[i+1][j];
}
}
System.out.println(s);
sc.close();
}
}
道歉。嘗試使用SE應用程序來回答,但你不能引用原代碼仔細檢查您的回覆的有效性。 –
而不僅僅是downvoting我的答覆,這將是知道什麼是錯誤的/不正確有關我的回答,請有用。 –