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"