그래서 나는 $로 바뀌는 모든 모음으로 단어를 인쇄하는 프로그램을 작성하려고합니다. 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);
}
}
프로젝트에 5 세트 중 하나 인 여름 프로젝트가 좋았지 만 그게 내가 본 적이없는 오류 일 뿐이므로 컴파일러는 초보자이기 때문에 무엇을해야할지 몰랐다. 도움을 주셔서 감사합니다. – user1560400