Scanner for long integer, Exception in thread “main” java.util.InputMismatchException

后端 未结 4 1520
情歌与酒
情歌与酒 2020-12-22 11:39

I am at the last step to finalize my program, however whenever I enter my integer (long) I get a input mismatch:

Compiler message: \"Exception in thread \"ma         


        
4条回答
  •  长情又很酷
    2020-12-22 11:56

    You should use:

    long credNumber = kbd.nextLong();
    boolean n = isValid(credNumber);
    

    as the value you enter (16 digits) is over the limit of int.

    Your validation method accepts long so, your code should work fine with above change.

    public static boolean isValid(long number)
    

提交回复
热议问题