Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Rani Singh   on Nov 21 In Java Category.

  
Question Answered By: Troy Kelley   on Nov 21

i am giving u a suggestion, just check, whether it is possible? i doubt
if there is any direct solution to it, but we can follow procedure like-

1. take one string array of some comfortable size to store each place's
word format.
2. now start scanning the number  in reverse, & take 2 hash maps- i am
asking u to take 2 hashmaps for the purpose like - whenever u want to translate
a number like 2345 in words- only ten's place will have totally different
wordings like ten, twenty, etc. So, one hashmap to specially store ten's place's
word format & then rest of the places have one , two , three, etc common, just
the thing is u have to append hundred to 3rd place from right(i.e in reverse
order) or thousand to 4th place from right. So, i am taking one hashmap for rest
of the places(excluding ten's place) & then i will use a switch case  to
identify- what i should append to rest of the places.

3.& whenever u will get a word for a single digit, just store it in 1st
place of string array, thus proceed from reverse side of the number & then to
finally obtain it in correct form, u can just print that string array in reverse
from array.lenght to 0.

4. like if i will store - 2345 as in reverse order

1st place of string array- five

2nd place ...............-fourty

3rd place.................-three hundred

4th place ...............-two thousand

& then correct string is obtained by reversing string array, which will
produce correct form- two thousand three hundred fourty five.

ok, i have tried to explain what i think, but not that nice approach,
so, if u get some better way, let me also know, what u will implement.


If you have any comments or questions, submit it on the message board.
NO spam/ads/job posting or you will be BANNED from this group. Exception can be
made it happen by notify me ahead of time.
all new members' message will be verified by me (spam..) before it get posted.

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on problem of converting a number into words using double Or get search suggestion and latest updates.


Tagged: