我编写的这段代码遇到了一些麻烦,因为我遇到了ArrayIndexOutofBounds
异常错误,我不知道发生了什么。我希望我的代码生成的是一个 char 数字数组。
这是代码:
public class testing {
static int k = 2;
public static void main(String args[]) {
int[] numArr = new int[] { 15, 18, 21 };
createChar(numArr, k);
}
public static char[] createChar(int numArr[], int k) {
char[] store = new char[k - 1];
for (int i = 0; i < k; i++) {
int divide = numArr[i] / 4;
int numStore = divide % 4;
charN(numStore, store, k);
}
return store;
}
public static char[] charN(int numStore, char store[], int k) {
for (int i = 0; i < k; i++) {
if (k == 0) {
} else {
store[k - 1] = (char) numStore;
k = k - 1;
}
}
System.out.print(store);
return store;
}
}
非常感谢!