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"));
}
}
How can I edit my code to let it ignore any character but still sum up the digit from the input? The error is Exception in thread "main" java.lang.NumberFormatException: For input string: "h"