One way to solve the exercise to express the removal of whitespaces by using the regular expression: \\s+ and passing it to String.replaceAll() with an empty string which is the character we replace whitespaces and tabs with.
On the other hand I am not sure why they want you to use a for loop to count the number of characters in the string, when String has a built-in length() method in Java. (Even if you decided to write the for-loop you would be relying on length(), but in that case your for-loop would just increment a counter.)