Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Main { public static void main(String[] args) { String [] a = { 3 cats?, 17, , 20 thousand! }; System.out.println( sumAll( a

public class Main { public static void main(String[] args) { String [] a = { "3 cats?", "17", "", "20 thousand!" }; System.out.println( sumAll( a ) ); // 13 } public static int sumAll( String[] a ) {

} public static int sumOne( String str ) {

} }

public static int sumOne( String str )

{

Return the sum of any digits in the string

For example, if s is "42 cats", return 6

If there are no digits, then it returns 0

Here's one way to check if a String of length 1 is a digit.

String x = a single character;

if ( x.compareTo("0") >= 0 && x.compareTo("9") <= 0 )

then x is "0", "1", "2", "3", "4", "5", "6", "7", "8", or "9"

Then you can safely use Integer.parseInt to convert the String to an int.

}

public static int sumAll( String[] a )

{

Call the sumOne method for each string in the array

Return the sum of all the returned values

}

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_2

Step: 3

blur-text-image_3

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

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

Java bytecode is stored in files with an extension of

Answered: 1 week ago

Question

Know how productivity improvements impact quality and value.

Answered: 1 week ago