在询问切换器的输入之前,字符串 asd 打印双倍,我现在感到绝望。我希望字符串“asd”只打印一次,但在我的情况下打印两次,我的猜测是错误或循环,抱歉,我是这里的新手,对编程很陌生
public class FruitBasket {
static String option;
static String choice1;
static int catcher;
static int counter1 = 1;
static int counter = 0;
static String eater = "e";
static Scanner sc = new Scanner(System.in);
static Stack<String> basket = new Stack();
static String switcher;
public static void main(String[] args) {
catching();
}
static void catching(){
System.out.println("Catch and eat any of these fruits: " + "'apple', 'orange', 'mango', 'guava'" );
System.out.println("A apple, O orange, M mango, G guava");
System.out.print("How many fruits would you like to catch? ");
catcher = sc.nextInt();
switches();
}
static void switches(){
while(counter1 < catcher) {
String asd = "Fruit " + counter1 + " of " + catcher + ":";
System.out.print(asd);
switcher = sc.nextLine();
switch (switcher) {
case "a":
basket.push("apple");
counter++;
counter1++;
break;
慕无忌1623718
相关分类