java中把char型数组转换成int型数组怎么做?

java中把char型数组转换成int型数组怎么做?如果现在有一个cha[] ch ={'5','7','9','2','4','5'}数组,把他转换成int型数组,程序代码应该怎么写?
public class TestArray {

public static void main(String[] args) {

char ch[] = {'3','5','2','4','0','1','8'};
int[] a ={};
for(int i=0;i<ch.length;i++){
a[i]=Integer.parseInt(String.valueOf(ch[i]));
System.out.print(a[i]);
}

}

}
我这么做的,编译没有问题,但是运行就出错了,为什么?

第1个回答  2008-11-04
public class Test94 {
public static void main(String[] args) {
char[] ch ={'5','7','9','2','4','5'};
int[] i = new int[ch.length];
for (int j = 0; j < ch.length; j++) {
i[j] = Integer.parseInt(ch[j]+"");
}
}
}
第2个回答  2008-11-04
我比较同意二楼的话。个人认为循环出来之后再加到数组里去。
第3个回答  2008-11-04
哪位大大能指出为什么错了么, 我是个新手
第4个回答  2008-11-04
3楼的正确!
相似回答