클래스에 대해 이처럼 작은 HW 문제를 수행하고 있습니다. 내 프로그램의 요점은 사용자 입력에서 구문에있는 모든 공백 문자를 계산하는 것입니다. for 루프에 도달 할 때까지 모든 것이 정상입니다. 루프에 중단 점을 두었고 벌금을 부과하고 공백 문자를 계산합니다. "주"java.lang.StringIndexOutOfBoundsException 스레드에서공백 문자 수 계산 - Java
예외 : 문자열 색인이 범위를 벗어 : 루프는 프로그램이 충돌 끝나는 날이 오류를 제공하지만 5
사람이 할 수 있다면 아주 이해가 안 돼요 올바른 방향으로 나를 가리켜 라.
import java.util.Scanner;
public class Cray {
public static void main(String[] args){
String phrase; // a string of characters
int countBlank; // the number of blanks (spaces) in the phrase
int length; // the length of the phrase
char ch; // an individual character in the string
Scanner scan = new Scanner(System.in);
// Print a program header
System.out.println();
System.out.println ("Character Counter");
System.out.println();
// Read in a string and find its length
System.out.print ("Enter a sentence or phrase: ");
phrase = scan.nextLine();
length = phrase.length();
// Initialize counts
countBlank = 0;
// a for loop to go through the string character by character
// and count the blank spaces
for(int i =0; i<=length; i++){
if(phrase.charAt(i)==' '){
countBlank++;
}
}
// Print the results
System.out.println();
System.out.println ("Number of blank spaces: " + countBlank);
System.out.println();
}
}
가 발생합니다 공백이 너무 BufferedReader로
공공 정적 무효 메인 (문자열 []에 args)를 사용하여 무시합니다 그리고 더 나는 "방금 당신이 모두 해결하도록 노력 아니에요없는 내 HW 문제.이 문제를 해결할 수 있다면 프로그램을 더 수정해야만하기 때문에 아직 완료되지 않았습니다. – recheej