How to break down a sentence String?
I have a class named SentenceStats
And inside SentenceStats I need to create a static method named calcStats that accepts a sentence as a String
and prints to the screen the following statistics:
a. The number of words (words are separated by a single blank space)
b. For each word in the String, print:
i. The word
ii. A hyphen (‐)
iii. The number of characters
iv. The number of uppercase letters
For example, if you passed in the String:
"A man, a plan, a canal, Panama"
The output would be:
7 words
A – 1 characters, 1 capitals
man, – 4 characters, 0 capitals
a – 1 characters, 0 capitals
plan, – 5 characters, 0 capitals
a – 1 characters, 0 capitals
canal,*‐*6 characters, 0 capitals
Panama – 6 characters, 1 capital
All I need is some hints as to where to start. What methods to use. Im fairly new to Java and this one is difficult.