我正在尝试搜索 alpabet 数组中的 char 是否等于 textCharArray 的元素。如果是这样,请做一些数学运算:从字母表中添加到 arrayList 值的字符数。但我收到一个错误:
java.lang.ArrayIndexOutOfBoundsException
问题应该出在cicles上。但我不知道如何正确修复它。编码:
outputText.setText("");
inputTextString = inputText.getText().toString().replace(" ", ""); //panaikinami tarpa
char[] textCharArray = inputTextString.toCharArray(); //seka paverciama char masyvu
int l = textCharArray.length;
char[] alphabet = {'A','B','C','D','E','F','G','H','I','K','L','M','N','O','P','Q','R','S','T','V','X','Y','Z'};
int alpLenght = alphabet.length;
System.out.println(alpLenght);
stringKey = inputKey.getText().toString();
int k = Integer.parseInt(stringKey);
List<Integer>keyList = new ArrayList<Integer>();
while(k > 0){
keyList.add(k%10);
k = k /10;
}
Collections.reverse(keyList);
int j = 0;
int temp;
for(int i = 0; i <= l; i++){
for(int ii = 0; ii < alpLenght; i++){
if(j < keyList.size()){
if(textCharArray[i] == alphabet[ii]){
temp = ii + keyList.get(j);
System.out.println("Uzkoduotas: " + temp);
}
j++;
}
else {
j = 0;
if(textCharArray[i] == alphabet[ii]){
temp = ii + keyList.get(j);
System.out.println("Uzkoduotas: " + temp);
}
}
j++;
}