package code;
public class Solution3 {
public static int sumOfDigit(String s) {
int total = 0;
for(int i = 0; i < s.length(); i++) {
total = total + Integer.parseInt(s.substring(i,i+1));
}
return total;
}
public static void main(String[] args) {
System.out.println(sumOfDigit("11hhkh01"));
}
}
如何编辑我的代码以让它忽略任何字符但仍然总结输入中的数字?错误是Exception in thread "main" java.lang.NumberFormatException: For input string: "h"