First Question is how do i take a string I have and return it with no spaces. trim()
only eliminates the first and last whitespace of the sentence(getNoSpaceString method).
String input = " Hello World ";
You can achieve this by:
String input2 = input;
input2 = input.replaceAll(" ", "");
Take a look here for more information
Second question:
Also I am trying to count the number of digit words my sentence has aka one is 1 digit word.
If you're trying to count number of words, then:
int words = input.trim().split(" ").length;
System.out.println("number of words: " + words);
Here's how split works Let me know it this isn't what you're looking for for 2nd question