我正在制作一个计算句子中单词的程序。空格不算数,标点符号不算数。我正在使用一个接收输入并输出答案的模块。但是不要担心,因为我认为这不是我的程序打印出这个的原因
Exception in thread "main" java.lang.StringIndexOutOfBoundsException:
String index out of range: 11
at java.lang.String.charAt(String.java:658)
at WordCount.main(WordCount.java:20)
public class WordCount{
public static void main(String[] args){
System.out.println("Please enter sentence");
String sentence= IO.readString();
System.out.println("Please enter minimum word length");
double minword= IO.readInt();
String word;
int wordletter=0;
int wordcount= 0;
int count= -1;
int end= sentence.length();
do{
count++;
char space= sentence.charAt(count);
if(Character.isLetter(space)){
boolean cut= Character.isSpaceChar(space);
if(cut== true)
word=sentence.substring(0,count);
count= 0;
wordletter= word.length();
end= end- wordletter;
if(wordletter< minword){
;
}else{
wordcount= wordcount+1;
}
}else{
;
}
}else{
;
}
}while(count!= end);
IO.outputIntAnswer(wordcount);
}
}