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)