A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
What does the program specification say you should count: spaces or whitespace? Read the JavaDocs for both methods and see which matches the spec and use it.Originally posted by John Todd:
in order to count spaces, should I use :
isWhitespace( ) or is SpaceChar( ) ??
How could a Character be able to tell you anything about words (other than single-letter words like "I" and "a")? Think about how you detect English words (try defining one for starters) in the context of a text file. Then translate that into a sequence of logic steps and finally code.which method in Character class counts the words ??
Every system may vary. Typically, whitespace is considered to include space " ", horizontal tab "\t" and newline "\n". However, the JavaDoc for Character.isWhitespace(char) saysOriginally posted by John Todd:
May I ask you what is the difference between the space char and white space ?
What that tells me is that you should never read JavaDocs before coffee. No wait, what that tells me is that the three I mentioned above are included in that much wider definition. But I would bet you that when your program is tested, only the three I mentioned will be considered (maybe carriage return if tested on a Mac). Regardless, using Character.isWhitespace(char) will count them all correctly.A character is considered to be a Java whitespace character if and only if it satisfies one of the following criteria:
It is a Unicode space separator (category "Zs"), but is not a no-break space (\u00A0 or \uFEFF). It is a Unicode line separator (category "Zl"). It is a Unicode paragraph separator (category "Zp"). It is \u0009, HORIZONTAL TABULATION. It is \u000A, LINE FEED. It is \u000B, VERTICAL TABULATION. It is \u000C, FORM FEED. It is \u000D, CARRIAGE RETURN. It is \u001C, FILE SEPARATOR. It is \u001D, GROUP SEPARATOR. It is \u001E, RECORD SEPARATOR. It is \u001F, UNIT SEPARATOR.
Consider Paul's rocket mass heater. |