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!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Mobile number problem  RSS feed

 
Savitha Gollamudi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Please help me with this..  Thanks in advancr
 
Ganesh Patekar
Bartender
Posts: 696
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!