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();
    }

As you can see I want to create the withdraw and deposit action using if, how can I assign the answer to character D or W to do this code. Can you guy show me how to do? Thanks a lot!

  • 1
    Use `answer.equals("D")` or `answer.equals("W")` to check equality. – shree.pat18 Jan 04 '15 at 10:42
  • See [this](http://stackoverflow.com/questions/4505357/what-is-the-difference-between-operator-and-equals-with-hashcode) for difference in == and equals – SMA Jan 04 '15 at 10:42

1 Answers1

0

You can use something like:

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

To make up for different case of the letters entered D or d etc.

Aashir
  • 2,621
  • 4
  • 21
  • 37