I am trying to create a method that will count number of zeros in a statement/numbers (numOfZero), that a string as input and returns the number of occurrence of ‘0’ in the string.
And if there is no zero it should return zero. I have used String.length() and String.CharAt(int index). but getting some errors. Any help?

Recommended Answers

It would help if you

  1. posted the code
  2. posted the errors and the corresponding line numbers

We can't answer questions in a vacuum.

Jump to Post

All 2 Replies

It would help if you

  1. posted the code
  2. posted the errors and the corresponding line numbers

We can't answer questions in a vacuum.

I want to add there are many ways to skin this animal.

Example: https://www.baeldung.com/java-count-chars

I see many solutions and the solution you use varies with choices about which Java, whether you want to go native, libraries, recursive or not.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.