I cant quite work out what i am doing wrong. I am trying to count the amount of digits in an inputted string but for example, if the number is 21 i want to count that as 1 inputted digit in the string.
So far i have the following but i can't work out how to count it as 1 integer rather than 2.
public static int countIntegers(String input) {
int count = 0;
for (int i = 0; i < input.length(); i++) {
if (Character.isDigit(input.charAt(i))) {
count++;
}
}
return count;
}
My issue is I want it to a string because there is a certain format the string has to be inputted in.