This week's book giveaway is in the Kotlin forum.We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

Mobile number problem

Savitha Gollamudi
Greenhorn
Posts: 1
Hello I'm unable to execute a problem please help me out with this
Problem statement : Person x has mobile number with '-' separations in different countries.  Consider this mobile number as input and produce output in the following manner i.e, for every 3 digits '-' should be added.
Input format : 75-25-85-641852-352
Output format: 752-585-648-523-52

Ganesh Patekar
Bartender
Posts: 696
23
Welcome to CodeRanch!   What so far have you tried? Please post you code (Use code tag to post code) although it has error or doesn't produce expected result, so we can see where you went wrong.

Ganesh Patekar
Bartender
Posts: 696
23
Savitha Gollamudi wrote:Input format : 75-25-85-641852-352
Output format: 752-585-648-523-52
I think you meant
Input: 75-25-85-641852-352
Output: 752-585-641-852-352
What output do you expect if input has no of digits not completely divisible by 3
Example:
Input: 75-25-85-64185-23
Output: What do you expect?

Fred Kleinschmidt
Bartender
Posts: 560
9
Your first task should be to develop the algorithm, try it out by hand on a test case, and only then should you start writing code.
One such algorithm would be to simply remove all dashes, then reparse the result to achieve the desired answer.