0
System.out.println("Do you want to deposite or withdraw? (D/W)");
String answer;
answer = input.nextLine();
if("D" === answer)// Thing need to help
{
System.out.println("Enter deposite ammount: ");
depositeAmmount = input.nextDouble();
System.out.printf("adding %.2f to account1\n\n", depositeAmmount);
acc1.Credit(depositeAmmount);
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(){
System.out.println("Enter withdraw ammount: ");
withdrawAmmount = input.nextDouble();
System.out.printf("differing %.2f to account1\n\n", depositeAmmount);
acc1.Withdraw(withdrawAmmount);
System.out.format("ballance of account1 is: %.2f\n", acc1.getBallance());
System.out.format("ballance of account2 is: %.2f\n", acc2.getBallance());
}
else{
System.out.println("The answer you input is invalid! Please input again!\n");
answer = input.nextLine();
}
正如你所看到的,我想使用if來創建提取和存款操作,如何將這個答案分配給字符D或W來執行此代碼。你可以向我展示怎麼做?非常感謝!如何使用if(answer =='D')?
使用'answer.equals( 「d」)'或'回答。等於(「W」)來檢查相等性。 – 2015-01-04 10:42:10
查看[this](http://stackoverflow.com/questions/4505357/what-is-the-difference-between-operator-and-equals-with-hashcode)==和等號的區別 – SMA 2015-01-04 10:42:57