2016-12-26 7 views
-3

本の検索に使用するシステムを作成したいと考えています。 else文以外は問題ありません。ケース1の場合、ユーザーがHarryPotterに入力すると、利用可能であることを表示する必要があります。ユーザーが何か他のものを入力すると、プログラムは使用できないと表示する必要がありますが、このようなコードを書くとエラーが発生します。ここでのコードは次のとおりです。arraylistを使用している場合のelse文

ArrayList<String> EnglishCategorie = new ArrayList<String>(); 
EnglishCategorie.add("HarryPotter"); 
boolean repeatAgain = true; 

while(repeatAgain) { 
    System.out.println("Please choose an option (between 1 and 5) :"); 
    System.out.println("Press 1 to search a book in English Categorie. 
      System.out.println("Press 2 to exit the program. "); "); 
    int choice = input.nextInt(); 
    switch (choice) { 
     case 1: 
      System.out.println("Please enter a book name: "); 
      bookName = input.nextLine(); 
      if(bookName == EnglishCategorie.contains("HarryPotter")) 
       System.out.println("It is available."); 
      else 
       System.out.println("It is not available."); 
      break; 
+1

何が問題なのですか?あなたはif文に問題があると言いましたが、問題が何であるかは言いませんでした。 – Carcigenicate

+0

while、switch、ifおよびelseブロックの括弧が欠落しています。それはあなたの最終的なコードで同じですか? – MrB

+0

あなたはエラーメッセージを投稿できますか? – Chip

答えて

0

この

if(bookName == EnglishCategorie.contains("HarryPotter")) 

booleanを返しcontains

if(EnglishCategorie.contains(bookName)) 

でなければなりません。 bookNameStringであり、はCollectionであり、String(s)です。

+0

私はあなたの提案をしましたが、プログラムには書籍名を入力してくださいと表示され、自動的には利用できません。 –

+0

@TarıkGölそれは別の質問です。さて、あなたは[この問題](http://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-nextint-or-other-nextfoo)を持っています。 –

+0

それは動作します!どうもありがとうございます。 @Elliott Frisch –

関連する問題