For this next assignment, we are going to combine working with Strings and arrays.
The user is to enter in a line of text (A sentence or two with a minimum of 10 words total). Your program will read the line of text and calculate the number of words in the sentence(s). It will then create an array that is the length of the number of words and store each word in the array. The program will then read the array from the last element to the first and print out the words in reverse order. Example: You enter the text. I am fine. How are you today? You read the input and count 7 words. (For this first program, any punctuation is counted as part of the word to which it is adjacent.) You create an array of length 7. So in position 0, the word "I" is stored, in position 2 "am" is stored. in position 3 "fine." is stored (any punctuation is stored with the word it is next to) etc. in position 6 (the 7th element), "today?" is stored. You will then USE THE ARRAY to print the sentence in reverse. So the actual output should look exactly as you see below: today? you are How fine. am I (Sounds like Yoda if you fixed the punctuation and caps!) (Today you are how? Fine am I!) This assignment will be due on Monday, May 4. We will also be having a short assessment next week. Stay healthy! Comments are closed.
|
Archives
May 2020
Categories |