我有一个方法,我正在工作,它的一部分较大的程序,但我认为我发布的代码就足够了。如果选项的作品,但如果不是
当我在我的菜单中选择选项1时,它可以正常工作,但是当我选择选项2时,它只是结束程序。任何人都可以发现问题吗?
解决的问题:选择== 1应该是2
可我也加入到了这个问题,这将是最好把推杆中的数据到一个数组,如果是的话,我应该在声明数组主类,超类或子类
static void addBook(){
String title,author;
int choice;
boolean onLoan;
loanbook book1; // TESTING ONLY
System.out.print("Press 1 for Fiction or 2 for Non Fiction: "); // sub menu for fiction and non fiction
choice = keyboard.nextInt();
if (choice == 1){
System.out.println("Please enter book title: ");
title = keyboard.nextLine();
title = keyboard.nextLine();
System.out.println("Please enter book author: ");
author = keyboard.nextLine();
onLoan = false; // not used yet
book1 = new fiction(title,author);
System.out.println(book1.toString());
}
else if (choice == 1) {
System.out.println("Please enter book title: ");
title = keyboard.nextLine();
title = keyboard.nextLine(); ;
System.out.println("Please enter book author: ");
author = keyboard.nextLine();
onLoan = false; // not used yet
book1 = new nonfiction(title,author);
System.out.println(book1.toString());
}
}
也许用'否则,如果(选择== 2){'... – Reimeus
这么简单的事,好点。谢谢。 – user2854120