我的嵌套if else语句出了问题。我正在输入一个项目标题,我试图这样做,如果我的数据库中不存在该项目标题,程序将告诉用户标题不存在。我的程序目前跳过else if语句应该输出“no entry”任何帮助,这将非常感谢。
else if (Option == 2) {
scan.nextLine();
System.out.println("item title");
title = scan.nextLine();
boolean found = false;
for (MediaItem mi : media){ if (mi.getTitle().equals(title) && mi.onLoan == true){
found = true;
System.out.println("already on loan");
break a;
} if (!flag) {System.out.println("This title does not exist in the library");
break a;}
}
System.out.println("Who are you loaning it to?");
loanedTo = scan.nextLine();
System.out.println("When did you loan it to them?");
dateLoaned = scan.nextLine();
答案 0 :(得分:1)
经过几次猜测和更多的澄清,我相信这就是你要找的东西:
System.out.println("Item Title:");
title = scan.nextLine();
boolean found = false;
for (MediaItem mi : media){
if (mi.getTitle().equals(title) && mi.onLoan == true){
found = true;
System.out.println("Already Loaned");
break;
}
}
if (!found) {
System.out.println("no entry");
}