Learning Goals In this lab, you will Use the for OBJ in CONTAINER loop to go over characters in the string Use if statements to compare the strings and characters Use if statements to detect when to output a singular noun Create and increment variables to count (use the accumulator pattern) Use string concatenation to create a new string to assemble the requested output Instructions Write a program that asks the user for a line of text and counts how many spaces, periods, or commas the text contains using the specified output format. Examples If the input is: Hello, world. the output is: There are 1 space, 1 period, and 1 comma. If the input is: Listen, Mr. Jones, calm down. the output is: There are 4 spaces, 2 periods, and 2 commas. Hints Review Figure 6.5.2 to see how to iterate over characters. Go over the string, character by character, and increment the counters for the requested characters. You will need a separate counter for every symbol that you are counting. Do not forget - initially, we do not have any characters counted, so the counter should be 0. You will need a separate check for each symbol to know whether to print its counter with a singular or a plural noun
Learning Goals In this lab, you will Use the for OBJ in CONTAINER loop to go over characters in the string Use if statements to compare the strings and characters Use if statements to detect when to output a singular noun Create and increment variables to count (use the accumulator pattern) Use string concatenation to create a new string to assemble the requested output Instructions Write a program that asks the user for a line of text and counts how many spaces, periods, or commas the text contains using the specified output format. Examples If the input is: Hello, world. the output is: There are 1 space, 1 period, and 1 comma. If the input is: Listen, Mr. Jones, calm down. the output is: There are 4 spaces, 2 periods, and 2 commas. Hints Review Figure 6.5.2 to see how to iterate over characters. Go over the string, character by character, and increment the counters for the requested characters. You will need a separate counter for every symbol that you are counting. Do not forget - initially, we do not have any characters counted, so the counter should be 0. You will need a separate check for each symbol to know whether to print its counter with a singular or a plural noun
Chapter8: Arrays
Section: Chapter Questions
Problem 8PE
Related questions
Question
Learning Goals
In this lab, you will
- Use the for OBJ in CONTAINER loop to go over characters in the string
- Use if statements to compare the strings and characters
- Use if statements to detect when to output a singular noun
- Create and increment variables to count (use the accumulator pattern)
- Use string concatenation to create a new string to assemble the requested output
Instructions
Write a program that asks the user for a line of text and counts how many spaces, periods, or commas the text contains using the specified output format.
Examples
If the input is:
Hello, world.
the output is:
There are 1 space, 1 period, and 1 comma.
If the input is:
Listen, Mr. Jones, calm down.
the output is:
There are 4 spaces, 2 periods, and 2 commas.
Hints
- Review Figure 6.5.2 to see how to iterate over characters.
- Go over the string, character by character, and increment the counters for the requested characters.
- You will need a separate counter for every symbol that you are counting.
- Do not forget - initially, we do not have any characters counted, so the counter should be 0.
- You will need a separate check for each symbol to know whether to print its counter with a singular or a plural noun
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT