나는 문자열의 모음, 자음, 공백 및 구두점의 수를 세는 프로그램을 만들고 있습니다. 다른 것으로 옮기기 전에 모음 검사기가 작동하는지 확인하고 있습니다. 논리적으로 작동하는 것처럼 보이는 루프를 만들었습니다. 자바 시각화기를 통해 실행 했으므로 모든 것이 체크 아웃됩니다. 그러나 BlueJ IDE를 통해 실행하면 오류가 발생합니다. It says : java.lang.StringIndexOutOfBoundsException : 문자열 인덱스가 범위를 벗어났습니다. 나는 그 문제가 무엇인지 전혀 알지 못한다. 나는 모든 도움에 감사 할 것이다. 이 사람이 스스로를 테스트하고자하는 경우 java visualizer에 대한 링크, 그리고 나는 아래 코드는 게시 한 :Java에서 루프에 문제가 있습니다. 설명의 설명
//**************************************************************
// Testing program for VCP program (temporary).
//
// @aaron_ford
// @version_1.0_11.9.17
//**************************************************************
public class VCPTest
{
public static void main(String[] args)
{
System.out.println("Enter a string.");
String user_str = "a vowel is here";
System.out.println("You entered: " + user_str);
char vowels[] = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};
// counter variables
int v_counter = 0;
int c_counter = 0;
int s_counter = 0;
int p_counter = 0;
int count = 0;
int str_compare = user_str.charAt(count);
for (; count < str_compare; count++)
{
str_compare = user_str.charAt(count);
for (int a:vowels)
{
if (a == str_compare)
{
v_counter++;
}
}
}
System.out.println("There are " + v_counter + " vowels.");
System.out.println("There are " + c_counter + " consonants.");
System.out.println("There are " + s_counter + " spaces.");
System.out.println("There are " + p_counter + " punctuation marks.");
}
}
' 'str_compare = user_str.charAt (count)'일 때
shmosel
for 루프 조건이'count
다음을 시도해보십시오 : for (char v : bev) if (c == v) v_counter ++;' – shmosel