嗨,我正在制作比萨饼项目,并且希望用户只选择1个基地,所以一旦他说“是”,那么厚底座就毫无疑问。
System.out.print("\nDo you want thick base?");
input = keyboard.nextLine();
choice = input.charAt(0);
if (choice == 'y'){
pizza.setPizzaBase(new PizzaBase("thick"));
}
//Thin base
System.out.print("\nDo you want thin base?");
input = keyboard.nextLine();
choice = input.charAt(0);
if (choice == 'y') {
pizza.setPizzaBase(new PizzaBase("thin"));
}
答案 0 :(得分:5)
一个不错的简单陈述!
System.out.print("\nDo you want thick base?");
input = keyboard.nextLine();
choice = input.charAt(0);
if (choice == 'y'){
pizza.setPizzaBase(new PizzaBase("thick"));
} else {
//Thin base
System.out.print("\nDo you want thin base?");
input = keyboard.nextLine();
choice = input.charAt(0);
if (choice == 'y') {
pizza.setPizzaBase(new PizzaBase("thin"));
}
}