gpt4 book ai didi

java - 字符.isDigit()错误: no suitable method found for isDigit(String)

转载 作者:行者123 更新时间:2023-12-01 07:44:04 24 4
gpt4 key购买 nike

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.");
}

根据扫描仪输入预期 true 或 false。不断向我抛出此错误:

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)

最佳答案

方法 Character.isDigit() 接受一个 char 作为输入 - 您试图向它传递一个 String

该错误描述了问题所在:

argument mismatch; String cannot be converted to char

关于java - 字符.isDigit()错误: no suitable method found for isDigit(String),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58296268/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com