Day#3 of Java Programming Practice- Longest word of a Sentence

Today's problem is finding longest word of a sentence.The twist being, in case any of the words has punctuation marks, the punctuation should be ignored while calculating the length of that word.

My first choice to separate each word in the sentence was by using a String Tokenizer, but when I looked in the documentation for the syntax, it told me that using split is a better idea.
This twist of ignoring punctuation mark got me thinking , and this is the program I wrote along with the output. Though it gives correct output, I felt it to be an ugly version.



I started looking on the net for a better solution, Though I didn't get an exact solution of this problem, I did get an interesting idea that helped in making the program look better. So here is the second version of my program.


 This made me realize that I need to work on learning regular expressions properly. And the learning notes will certainly make it to a post on this blog. 
Signing off for today, will come back with a new program tomorrow.

Comments

Popular posts from this blog

Book Review: Those Pricey Thakur Girls

Day# 5 of Java Programming Practice- Change the first letter of each word in a sentence to Uppercase.