Practice Problems - String OperationsThese problems will help you learn to use various programming concepts.
|
Intro to Turing (2014)
Practice Problems
Unless otherwise specified, you can just declare the string at the beginning of your program. You don't have to ask for the string to be entered.
1. Write a program to count all occurrences of the letter 't' in a sentence.
1. Write a Processing program to read a series of words (entered in a text field) and count the words until the word 'stop' is entered (don't include counting 'stop')
2. Write a program that computes the average length of words in a sentence. Assume that there are no punctuation marks in the sentence.
3. Write a program to change any "or" endings of words to "our". For example it should change "color" to "colour". Improve it so that it does not affect the word "or" itself
4. Write a program to take a first and last name entered in a text field and output it in the order last, first. (ex. enter "Joe Williams" and output "Williams, Joe".
5. Write a program to take a sentence and output it in the reverse order. (ex. enter "The dog ran." and output "Ran dog the.")
6. Write a program to find the positions of all occurrences of the substring "at'" in the sentence, "I looked at the fat cat and then put on my hat."
1. Write a program to count all occurrences of the letter 't' in a sentence.
1. Write a Processing program to read a series of words (entered in a text field) and count the words until the word 'stop' is entered (don't include counting 'stop')
2. Write a program that computes the average length of words in a sentence. Assume that there are no punctuation marks in the sentence.
3. Write a program to change any "or" endings of words to "our". For example it should change "color" to "colour". Improve it so that it does not affect the word "or" itself
4. Write a program to take a first and last name entered in a text field and output it in the order last, first. (ex. enter "Joe Williams" and output "Williams, Joe".
5. Write a program to take a sentence and output it in the reverse order. (ex. enter "The dog ran." and output "Ran dog the.")
6. Write a program to find the positions of all occurrences of the substring "at'" in the sentence, "I looked at the fat cat and then put on my hat."