package com.seqlist;
public class SeqList {
/**
* @java.lang.ArrayIndexOutOfBoundsException
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int [] Adata={3,2,5,1,2,3,4,3};
int [] Bdata={6,4,3,2,4,5,6};
int flag=0;
int n=Adata.length;
int m=Bdata.length;
int [] Cdata={};
int i=0;
int x=Cdata.length;
while(i<n&&i<m){
//數組越界,為什麼為什麼為什麼????
Cdata[i]=(Adata[i]+Bdata[i]+flag)%10;
flag=(Adata[i]+Bdata[i]+flag)/10;
i++;
}
for(;i<n;i++){
Cdata[i]=(Adata[i]+flag)%10;
flag=(Adata[i]+flag)/10;
}
for(;i<m;i++){
Cdata[i]=(Bdata[i]+flag)%10;
flag=(Bdata[i]+flag)/10;
}
x =Math.max(m,n)+flag;
if(flag==1)Cdata[x-1]=1;
for(int j=0;j<Cdata.length-1;j++) {
System.out.print(Cdata[j]);
}
}
}
int [] Cdata={};
int i=0;
int x=Cdata.length;
System.out.println(x);
輸入結果為0,
說明數組Cdata長度為0啊
改成 int [] Cdata=new int[10];就可以了