int不等于string

时间:2017-09-22 01:50:02

标签: java if-statement int java.util.scanner

我正在尝试写if语句设置条件,如果用户输入除了整数之外,它将打印出一条消息并退出。我试过==和!=字符串和类似的东西无济于事。

感谢任何帮助 艾利

    System.out.println("What is the reserve price? ");
    int reserve = scanner.nextInt();


    System.out.println("What is the bid of Person 1? ");
    int p1 = scanner.nextInt();

    System.out.println("What is the bid of Person 2? ");
    int p2 = scanner.nextInt();



    if (p1 < reserve && p2 < reserve){
        System.out.println("No one wins because the reserve price of $"+ reserve+ " was not met.");
        System.exit(0);
    }else if (p1 > p2){
        System.out.println("Person 1 wins for $"+p1+".");
    }else if (p2 > p1){
        System.out.println("Person 2 wins for $"+p2+".");
    }
    if (p1==p2){
        System.out.println("It's a tie at $"+p1+".");
    }

0 个答案:

没有答案