同じ文字が連続して並ぶ時、2回目以降の同じ文字を削除して出力する以下のコードの穴埋め問題3問(charAtメソッドを使うよう指示)で、以下のように回答したのですが、エラーになりました。
9行目while ( inputString.charAt(stringIndex) != 0000)
の部分にエラーがあるようです。スペースに至るまでの文字を取り込もうと思ったのですが、どう改善したら良いでしょうか。
java
1inputString = inputString.trim(); // Remove any leading and trailing blanks 2 String result = "", currentWord = "", nextWord = ""; 3 int stringLength = inputString.length(); // Length of the input string 4 int stringIndex = 0; // Index for input string 5 6 while (stringIndex < stringLength) { 7 8 // (Question1) Get the next word in inputString 9 while ( inputString.charAt(stringIndex) != 0000){ 10 11 nextWord = nextWord + inputString.charAt(stringIndex); 12 stringIndex++; 13 } 14 // (Question2) Check if nextWord is the same as currentWord 15 if ( nextWord != currentWord ) { 16 17 result = result + nextWord;//(Question3) 18 } 19 20 stringIndex++; 21 currentWord = nextWord; 22 nextWord = ""; 23 } 24 25 return result.trim(); // Remove any leading and trailing blanks from result