Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please implement The following...... public int getSumOfNumbers(String s) method to return the total of all integers found in the parameter String s. Input Integers are

Please implement The following......

public int getSumOfNumbers(String s) method to return the total of all integers found in the parameter String s.

Input Integers are separated from other parts with one or more spaces.

If necessary, you may add methods to this class.

Input1: 12 some text 3 7

Output1: 22 (Which is 12 + 3 + 7)

----------------------------------------------

Input2: 12 some text3 7

Output2: 19 (Which is 12+7, number 3 in this example is connected to the text3 and there is no space so do not consider it!)

***** Pleae implement this using Regular Expressions ********

********Use the following as Main*******

class DriverMain{ public static void main(String args[]){ Scanner in = new Scanner(System.in); Gather q1 = new Gather(); String s = in.nextLine(); System.out.print(q1.getSumOfNumbers(s));

} }

******The Gather class referenced from main as follows.******

class Gather{ public int getSumOfNumbers(String s) {

} }

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

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions