本の検索に使用するシステムを作成したいと考えています。 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;
何が問題なのですか?あなたはif文に問題があると言いましたが、問題が何であるかは言いませんでした。 – Carcigenicate
while、switch、ifおよびelseブロックの括弧が欠落しています。それはあなたの最終的なコードで同じですか? – MrB
あなたはエラーメッセージを投稿できますか? – Chip