小编Bro*_*Rob的帖子

Character.isDigit()错误:找不到适用于isDigit(String)的方法

Kepp使用Character.isDigit()时出现错误

我在其他地方进行了查找并对其进行了很好的测试,但在这里我仍然遇到此错误。

  Scanner scnr = new Scanner(System.in);
  boolean hasDigit;
  String passCode;

  hasDigit = false;
  passCode = scnr.next();

  hasDigit = Character.isDigit(passCode);

  if (hasDigit) {
     System.out.println("Has a digit.");
  }
  else {
     System.out.println("Has no digit.");
  }
Run Code Online (Sandbox Code Playgroud)

根据扫描仪的输入,期望为真或假。不断向我抛出此错误:

CheckingPasscodes.java:12: error: no suitable method found for isDigit(String)
  hasDigit = Character.isDigit(passCode);
                      ^
method Character.isDigit(char) is not applicable
  (argument mismatch; String cannot be converted to char)
method Character.isDigit(int) is not applicable
  (argument mismatch; String cannot be converted to int)
Run Code Online (Sandbox Code Playgroud)

java compiler-errors

0
推荐指数
1
解决办法
63
查看次数

标签 统计

compiler-errors ×1

java ×1