如何使用if(answer ==' D')?

时间:2015-01-04 10:40:51

标签: java

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来执行此代码。你能告诉我该怎么办?非常感谢!

1 个答案:

答案 0 :(得分:0)

您可以使用以下内容:

if(answer.equalsIgnoreCase("D")) {
    // your code
}

弥补输入D或d等字母的不同情况。