139k views
0 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 Lib
by
3.1k points

1 Answer

5 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 Mathandy
by
3.3k points