This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Digits to Words  RSS feed

 
Ranch Hand
Posts: 598
3
Google App Engine jQuery Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I am trying to convert digits to words... the above program converts digits to words but the problem is it is printing words in reverse. How to correct my code ?
 
lowercase baba
Bartender
Posts: 12627
50
Chrome Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) turn off your computer.
2) get some pencil and paper
3) work through the steps on how YOU would do it by hand, if you have nothing but the supplies in front of you. Literally write down the steps.
4) revise the steps until a young child could follow them without needing to ask you questions.

when you've done the above, you will know how to write your code.


Another tip - when you do write your code, don't write 24 (or probably more) before you compile and test.

split your process into component parts and write methods for each, instead of globbing all this into a single chunk of code. Converting a digit to words is in no way dependent on how you get the digits. So, at minimum, you should have a method that takes a digit as a parameter and converts it. Then you can call it as often as you want.

Splitting a number into individual digits has nothing to do with printing out those digits, so that should be a separate method.

Test your methods independently.
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bobby Sharma wrote:the above program converts digits to words but the problem is it is printing words in reverse. How to correct my code ?


Use a structure (and there are plenty to choose from). What you have written is a procedure, and it's plainly not doing exactly what you want.

So: How do YOU think you might get it to process digits in the correct sequence? (Hint: it might involve more than one phase)

Winston
 
Bobby Sharma
Ranch Hand
Posts: 598
3
Google App Engine jQuery Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for fabulous tips
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!