这是代码:
package classes;
import java.util.*;
public class Introduction {
Scanner Input = new Scanner(System.in);
int classChoose;
boolean repeat = false;
public void Introduction() {
System.out.println("\t===THE QUEST FOR PERSEPOLIS===\tv 1.0\n");
System.out.println("Please choose a class: ");
System.out.print("(1)Elite Knight\t");
System.out.print("(2)Dawnguard\n");
System.out.print("(3)Archer\t\t\t");
System.out.print("(4)Barbarian\n");
System.out.print("(5)Mage\t\t\t");
System.out.print("(6)Swordsman\n");
System.out.println("(7)Crossbowman\t");
do {
try {
repeat = false;
classChoose = Input.nextInt();
while(classChoose < 1 || classChoose > 7) {
repeat = false;
System.out.println("Error. Enter a number between 1 and 7(inclusive).");
classChoose = Input.nextInt();
}
}
catch(InputMismatchException e) {
repeat = true;
System.err.println("Caught: "+e);
Input.nextLine();
}
}while(repeat = true);
switch(classChoose) {
case 1: chooseKnight();
break;
case 2: chooseGuard();
break;
case 3: chooseArcher();
break;
case 4: chooseBarbarian();
break;
case 5: chooseMage();
break;
case 6: chooseSwordsman();
break;
case 7: chooseCrossbowman();
break;
}
}
public static void chooseKnight() {
System.out.println("You have chosen the Elite Knight. You will be briefed and then you shall be set "
+"on your quest!");
}
static void chooseGuard() {
System.out.println("You have chosen the Dawnguard. You will be briefed and then you shall be set "
+"on your quest!");
}
static void chooseArcher() {
System.out.println("You have chosen the Archer. You will be briefed and then you shall be set "
+"on your quest!");
}
static void chooseBarbarian() {
System.out.println("You have chosen the Barbarian. You will be briefed and then you shall be set "
+"on your quest!");
}
static void chooseMage() {
System.out.println("You have chosen the Mage. You will be briefed and then you shall be set "
+"on your quest!");
}
static void chooseSwordsman() {
System.out.println("You have chosen the Swordsman. You will be briefed and then you shall be set "
+"on your quest!");
}
static void chooseCrossbowman() {
System.out.println("You have chosen the Crossbowman. You will be briefed and then you shall be set "
+"on your quest!");
}
}
每次我运行它时,程序都会提示我选择我的班级。在我输入我的选择后,程序不会继续执行 do 循环下方的 switch 语句。有人可以帮我解决这个问题吗?
-卡尔文