私はソフトウェアテストクラスのプログラムに取り組んでいます。私は、特定の単語を見つけてそれを期待される結果と比較するために、文字列を反復するループを作成する必要があります。私が抱えている問題は、ループが文字列の最初の単語だけを出力することです。私の人生は私が間違っていることを理解することはできません。助けてください。あなたはif
外c
の設定を移動する必要がありループ印刷の最初の単語のみ
String input = "Now is the time for all great men to come to the aid of their country";
String tempString = "";
char c = '\0';
int n = input.length();
for(int i = 0; i<n; i++)
{
if(c != ' ')
{
c = input.charAt(i);
tempString = tempString + c;
}
else
{
System.out.println(tempString);
tempString = "";
}
}