【发布时间】:2020-08-17 04:56:39
【问题描述】:
//Choice of choosing a dog or a cat
String pet = input.next();
switch (pet.charAt(0)) {
case 'a' -> {
System.out.println("What is your dog's name? ");
String dogsName = input.next();
System.out.println("Your Character's Name is: " + playerName + "\nYour Pet's Name is: " + dogsName);
}
case 'b' -> {
System.out.println("What is your cat's name? ");
String catsName = input.next();
System.out.println("Character Name: " + playerName + "\nPet Name: " + catsName);
}
default -> System.out.println("That is not a valid option. Please choose again.");
}
input.close();
}
我找不到可以将其带回案例 a 并重复使用的循环,直到用户使用其中一个选项回答,任何帮助都会很棒!谢谢
【问题讨论】: