在我的程序中,用户必须选择他们想要做的事情,然后点击选项旁边的数字,然后点击回车。
现在我有它,所以任何不是选择的数字都会出错,但现在我想确保如果用户输入字母,例如“fadhahafvfgfh”,它会显示错误
这是我的代码...
import java.util.Scanner;
public class AccountMain {
public static void selectAccount(){
System.out.println("Which account would you like to access?");
System.out.println();
System.out.println("1 = Business Account ");
System.out.println("2 = Savings Account");
System.out.println("3 = Checkings Account");
System.out.println("4 = Return to Main Menu");
menuAccount();
}
public static void menuAccount(){
BankMain main = new BankMain();
BankMainSub sub = new BankMainSub();
BankMainPart3 main5 = new BankMainPart3();
Scanner account = new Scanner(System.in);
int actNum = account.nextInt();
if (actNum == 1){
System.out.println("*Business Account*");
sub.businessAccount();
}
else if (actNum == 2){
System.out.println("*Savings Account*");
main.drawMainMenu();
}
else if (actNum == 3){
System.out.println("*Checkings Account*");
main5.checkingsAccount();
}
else if (actNum == 4){
BankMain.menu();
}
}
}