19,157 views
28 votes
28 votes
Assume: String sentence = "The quick brown fox jumps over the lazy dog."; Write Java statements that will count and display the total number of the character 'o' in the string.

User Stativ
by
2.6k points

1 Answer

11 votes
11 votes

Answer:

You need a loop to iterate through each character in the string, and compare the character at each iteration to the character you are searching for.

If it matches, you increment the counter variable because you have to store the number of times you find it, so that you can print it later.

Assume: String sentence = "The quick brown fox jumps over the lazy dog.&quot-example-1
User AJReading
by
2.5k points