我正在开发软件测试课程。我需要创建一个循环遍历一个字符串,以便找到一个特定的单词,然后将其与预期结果进行比较。我遇到的问题是我的循环只打印出字符串的第一个单词。我不能为了我的生活找出我做错了什么。请帮忙。仅循环打印第一个字
这里是我的代码:
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 = "";
}
}