Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!