2017-12-21 4 views
0
  1. ユーザが文字列を入力します。Javaの戻り値は、文字列内の猫と犬の発生に依存しますか?

  2. 猫と犬の時間が同じであればtrue、そうでなければfalseが返されます。

  3. 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:+演算子は文字列引数の定義されていません。

任意の提案は、本当に

+1

NO必要性を削除しません.three(word)); ' – meditat

答えて

2

+を使用し、文字列と変数をCONCATするにはenough.Remove ,歓迎です。 、+応答:

System.out.println("Number of times cat and dogs appear in your word: " + response.three(word)); 
0
System.out.println("Number of times cat and dogs appear in your word: " + response.three(word)); 

、 `ライン で`のSystem.out.println( "回猫の数と犬が自分の言葉で表示される" `のcomma

関連する問題