
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Complete this program and count how many letters e are in the given string. For example, if the string is "redeemed", then the count is 4. Use a for loop.
![### Java Program to Count Specific Characters in a String
The following Java code is a template for counting occurrences of a specific character ('e') in a given string. The example provided counts the number of times 'e' appears in the word "redeemed", which should result in a count of 4. You are required to complete the program by implementing a `for` loop.
#### Code Template:
```java
public class Strings
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String word = in.next();
int count = 0;
for (/* Your code goes here */)
{
/* Your code goes here */
}
System.out.println("word: " + word);
System.out.println("count: " + count);
}
}
```
#### Instructions:
1. **Input Section**:
- The program takes a single input string from the user.
2. **Initialization**:
- An integer `count` is initialized to 0, which will keep track of the number of 'e' characters.
3. **Loop to Implement**:
- You need to fill in the `for` loop to iterate through each character in the string.
- Inside the loop, check if the current character is 'e'. If so, increment the `count`.
4. **Output**:
- The program outputs the given word and the count of 'e' characters.
5. **Button**:
- There is a "Check" button for executing the code to see if it produces the expected result.
This exercise helps in understanding basic string manipulation and usage of loops in Java.](https://content.bartleby.com/qna-images/question/3c6dd66e-2117-4fef-af3a-066ea689cabb/2cd4415d-823e-4959-b134-1a99ee3725f7/6liabiu_thumbnail.png)
Transcribed Image Text:### Java Program to Count Specific Characters in a String
The following Java code is a template for counting occurrences of a specific character ('e') in a given string. The example provided counts the number of times 'e' appears in the word "redeemed", which should result in a count of 4. You are required to complete the program by implementing a `for` loop.
#### Code Template:
```java
public class Strings
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String word = in.next();
int count = 0;
for (/* Your code goes here */)
{
/* Your code goes here */
}
System.out.println("word: " + word);
System.out.println("count: " + count);
}
}
```
#### Instructions:
1. **Input Section**:
- The program takes a single input string from the user.
2. **Initialization**:
- An integer `count` is initialized to 0, which will keep track of the number of 'e' characters.
3. **Loop to Implement**:
- You need to fill in the `for` loop to iterate through each character in the string.
- Inside the loop, check if the current character is 'e'. If so, increment the `count`.
4. **Output**:
- The program outputs the given word and the count of 'e' characters.
5. **Button**:
- There is a "Check" button for executing the code to see if it produces the expected result.
This exercise helps in understanding basic string manipulation and usage of loops in Java.
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 nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

Knowledge Booster
Similar questions
- Using a Java application write a for loop to sum all the squares of numbers between 1 and 15. Output the sum.arrow_forwardConvert the following for loop into do-while loop : for(int c =11; c>=0; c-=2) System.out.printIn("Count: "+ c);arrow_forward2. Write a program that uses a while loop to play a number guessing game. The computer should pick a number using random number generation and then continue asking the user to guess the number until they get it right. For each, gues, the computer should tell the user if the guess is too high or too low or is correct. 3. Using nested for loops, right a program that displays a bar chart (using asterisks) for a number entered by the user. For example, if the user enters 4, the bar chart looks like this:arrow_forward
- Write a while loop that prints the multiples of 3 from 300 down to 3. The programming language is java.arrow_forwardConsider the following program that contains a nested loop. j = while j> 0 : k = 0 while print("#", k = k + 1 print() j = j - 1 end Complete the program so that it prints the following 6 lines exactly:arrow_forwardConstruct a single for loop to print out the following lines. You may use as many variables as you wish, but you may not use multiple loops. 4 4 4 8 2 7 16 1 10 32 0.5 13 64 0.25 16arrow_forward
- n a while loop, generate a random integer from 0 to 9. Use srand() only once. Keep track of the number of iterations and quit the loop when the random integer is equal to 5. Report the number of iterations.arrow_forwardA semicolon (;) is necessary at the end of which type of the loop? All loops do-while while forarrow_forwardWrite a for loop that will print the lower case letters of the alphabet backwards. Do not use ASCII codes.arrow_forward
- in phython langage Write a while loop that will print all the numbers between 200 and 300 (200 and 300 included) that are divisible by 3 but not divisible by 6. Your output should include the following numbers: 201 207 213 219 225 231 237 243 249 255 261 267 273 279 285 291 297arrow_forward12. Write a loop of the specified type that sums up the even integers between 1 and 21. a. a while loop b. a for looparrow_forwardWrite a for loop that prints out all the numbers from 100 to 1 in descending orderarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education