所以我想賴特程序來打印一個單詞,所有的元音換成$。在java中是 。線程主異常java.lang.StringIndexOutOfBoundsException:字符串索引超出範圍:6
我一直得到這個錯誤exception in thread main java.lang.StringIndexOutOfBoundsException: String index out of range: 6
當我運行它,它編譯罰款。 這是代碼。
import java.util.*;
public class SummerFour
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int cnt = 0;
String word;
String output = "";
char letter = 'x';
System.out.print("enter word to test: ");
word = keyboard.nextLine();
do {
cnt++;
letter = word.charAt(cnt - 1);
if (letter == 'a' || letter == 'i' || letter == 'e' || letter == 'u' || letter == 'o')
{
letter = '$';
}
}
while (cnt <= word.length());
System.out.println(word);
}
}
謝謝是的,它是一個夏季項目,是一個項目中五個項目中的一個,但這就是我所需要的,只是一個我從未見過的錯誤,它編譯成一個初學者,我不知道該怎麼做。所以謝謝你抽出時間幫忙。 – user1560400 2012-07-29 18:58:47