if(!"D".equalsIgnoreCase(answer) || !"W".equalsIgnoreCase(answer)){
System.out.println("The answer is invalid!Please input again!");
answer = input.nextLine();
}else if(answer.equalsIgnoreCase("D")){
System.out.println("Enter deposite ammount: ");
depositAmmount = input.nextDouble();
System.out.printf("adding %.2f to account1\n\n", depositAmmount);
acc1.Credit(depositAmmount);
//display balance
System.out.format("ballance of account1 is: %.2f\n", acc1.getBallance());
System.out.format("ballance of account2 is: %.2f\n\n", acc2.getBallance());
}
else if(answer.equalsIgnoreCase("W")){
System.out.println("Enter withdraw ammount: ");
withdrawAmmount = input.nextDouble();
System.out.printf("differing %.2f to account1\n\n", withdrawAmmount);
acc1.Withdraw(withdrawAmmount);
//display balance
System.out.format("ballance of account1 is: %.2f\n", acc1.getBallance());
System.out.format("ballance of account2 is: %.2f\n", acc2.getBallance());
}
我正在尝试使用存款和绘制一个简单的应用程序。但它有一个错误,当我用!equals
确保用户必须输入D
或W
和其他键将再次输入,直到输入正确的键,但在这里它不工作和输入D
或W
它不能识别通知输入无效。比较字符串使用if(!“D”.equalsIgnoreCase(answer))不起作用
我需要一些帮助。
首先注意到错误,但是您可能希望在答案中使用格式(即'||'和'&&') –