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

Bro*_*Rob 0 java compiler-errors

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)

Jas*_*son 6

该方法Character.isDigit()采用a char作为输入-您正尝试将其传递给String

该错误描述了问题所在:

论据不匹配;字符串不能转换为char