【发布时间】:2014-11-29 09:51:35
【问题描述】:
public class Task {
public static void main(String[] args) {
String text ="a subject is the noun that is doing the main verb.";
int[] field = new int[26];
int xy = 0; //xy will be the total number of the letter in the sentence
char cd = 'a';
for (int ef = 0; ef<= 25; ef++){
for (int ab = 1; ab<= text.length(); ab++){
if (cd == text.charAt(ab)){ // Eclipse says that this line has problem (at CopyOfAufgabe_2.main(CopyOfAufgabe_2.java:13)
field[ef]=field[ef]+1;
xy++;
}
}
cd++;
}
}
}
``这个任务有两个目的:
1. find the total number of letters in the sentence
2. find the number of respective letter (i.e. how many "a"s, how many "b"s, etc. The numbers are assigned to the field created in the fifth line (one number for each object)) (It is assumed that every letter in the sentence is not capitalized.)
错误信息显示:
线程“主”java.lang.StringIndexOutOfBoundsException 中的异常:字符串索引超出范围:42 在 java.lang.String.charAt(未知来源) 在 CopyOfAufgabe_2.main(CopyOfAufgabe_2.java:13)``
【问题讨论】:
标签: java eclipse string indexoutofboundsexception