我如何才能获得if if语句起作用?

时间:2018-11-08 22:19:26

标签: java

所以我的问题是这样的:当我告诉我存入3时,它显示错误消息。 为什么这样做呢? 我总是每次都得到“钱不够”。

String PAYH1 = scan.nextLine();
if (PAYH1.equals("PAYH1"))
{
    System.out.println("please enter amount amout of money you wish to desposit (in Euro's).");
    Scanner s = new Scanner(System.in);
    int deposit = s.nextInt();
    int price;
    price  = 2;
    int sum = deposit - price;
    if (sum > 0)
    {
        System.out.println("Not enough money!");
    }
    else
    {
        System.out.println("Thank you for visiting!");
        System.out.println("You have " + sum + " cent(s) in exchange.");
    }

1 个答案:

答案 0 :(得分:1)

怎么样:

if (sum < 0)
{
    System.out.println("Not enough money!");
}
else
{
    System.out.println("Thank you for visiting!");
    System.out.println("You have " + sum + " cent(s) in exchange.");
}
相关问题