Question
Write the countDigits method that returns the number of times that a digit appears in text, which is a String that may be empty or
Write the countDigits method that returns the number of times that a digit appears in text, which is a String that may be empty or may contain words and digits. For example: countDigits("I told him 100 times to stop") returns 3 because the string 100 contains three digits and appears in text. Note, Your method returns 0 if presented with the empty string; You may use only the String methods used in class: charAt( int ), indexOf( char)
and/or length(); Your method can use at most one Java iteration statement (either a for, a while
or a do-while statement); and Your method may go through the text only once. static int countDigits( String text ) { String digits = "0123456789"; int count = 0;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started