catcatdoghotdog
和returns TRUE
以来cat = 2
= dog = 2
//我的代码
public String three (String str)
{
int cat = 0;
int dog = 0;
for(int a = 0; a < str.length() - 2; a++)
{
if (str.substring(a, a+3).equals("cat"))
{
cat++;
}
if (str.substring(a, a+3).equals("dog"))
{
dog++;
}
}
if(dog == cat)
{
return "TRUE";
}
else
{
return "FALSE";
}
}
System.out.println("Number of times cat and dogs appear in your word: " , + response.three(word)); // doesn't work...
ERROR
:String运算符未定义+运算符。
任何建议,真的很受欢迎
要连接字符串和变量,使用+
就足够了。移动,
。
System.out.println("Number of times cat and dogs appear in your word: " + response.three(word));
System.out.println("Number of times cat and dogs appear in your word: " + response.three(word));
删除comma