private void CreateAccount() {
// TODO Auto-generated method stub
String firstName, accountType="";
double initialDesposit = 0;
boolean valid = false;
int Current = 1;
int Saving = 2;
while (!valid){ //Only can select current or saving account
System.out.println("Enter account Type");
System.out.println("1:Current");
System.out.println("2:Saving");
accountType = keyboard.nextLine(); //User Input of the Account Type
if (accountType.equalsIgnoreCase("Current") || accountType.equalsIgnoreCase("Saving")|| accountType.equals(1) || accountType.equals(2)){
valid = true; //If selection is true
}else{
System.out.println("Invalid");
}
}
我想让它,当用户显示选项,他们可以选择数字或字母的选项,而不是输入“保存”用户只需按“2”并记录为保存。如何接受整数或字符串JAVA
字符串不能与整数,试试这个ACCOUNTTYPE .equals(“1”)accountType.equals(“2”) –
因此,查找'accountType.equalsIgnoreCase(“Current”)|| accountType.equalsIgnoreCase( “1”)'? – MadProgrammer