Wednesday, February 1, 2012

Lab 8: Words and Vowels

In this lab you will write a program that asks the user to type in some sentences and then tells him how many words and how many vowels (a, e, i, o, u) there are in the text he typed in. Here is a sample transcript:
I will count your vowels. Enter your sentences.
Hit enter when done
Sentence (hit ENTER when done):Once upon a midnight dreary
Sentence (hit ENTER when done):while I pondered
Sentence (hit ENTER when done):weak
Sentence (hit ENTER when done):and
Sentence (hit ENTER when done):weary
Sentence (hit ENTER when done):
There are 20 vowels.
There are 11 words.

You can assume that there is always a space between every two words, but remember that there could be a line with just one word, and no spaces, as the above example shows.

Hint: use Scanner.nextLine() to read the whole line.

Hint: use String.charAt

As always, turn it in at the dropbox.cse.sc.edu, Lab 8.

No comments: