Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions