| Author |
Word Conversion
|
Dishant Verma
Greenhorn
Joined: Feb 09, 2012
Posts: 25
|
|
How to convert NUMBER into CHARACTERS using "COLLECTIONS and GENERICS" ..?
Eg:
Number: 76237
Word Conversion: Seventy Six Thousand Two Hundred Thirty Seven
Dishant Verma
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 3143
|
|
Dishant Verma wrote:How to convert NUMBER into CHARACTERS using "COLLECTIONS and GENERICS" ..?
First you figure out how to do it "manually", without Java or any other programming language. You write down the steps--very basic, simple, precise, well-defined steps--with pencil and paper, and then you step through them by hand, and then when you find out you made some mistakes, you erase, and you correct, and you try again, and you repeat this process until you're pretty sure you have it right.
Then you convert those steps from English (or whatever language you're most comfortable with) into Java, and if collections and/or generics are a good fit for that conversion, you use them, and if not, you don't.
|
 |
Dishant Verma
Greenhorn
Joined: Feb 09, 2012
Posts: 25
|
|
"I have used this. But it is upto 99,999. But I want to enter any number having length 'n'....
And How can I eliminate if-else to make it more standardise.?"
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 3143
|
|
And note that this site is NotACodeMill.(⇐click) You are expected to ShowSomeEffort(⇐click) and ask a specific question about the specific parts that are giving you trouble.
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 3143
|
|
Okay, I'm sorry, this is too exasperating. I cannot help you. I hope that somebody else will have more patience than I.
Good luck!
|
 |
Dishant Verma
Greenhorn
Joined: Feb 09, 2012
Posts: 25
|
|
Hey sorry Jeff I am new to this,
so I didn't knew this....
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 26720
|
|
Dishant Verma wrote: . . . "I have used this. But it is upto 99,999. But I want to enter any number having length 'n'....
And How can I eliminate if-else to make it more standardise.?"
Back to your pencil and paper. You can use / and % repeatedly. But you would require a loop.
Also remember the value of a three-digit number is the value of the two-digit number with “howeverMany hundred” added. So you don’t need the > 100 test.
You would add spaces and “and” or hyphens (eg twenty-three) as appropriate.
I do not think you should put eleven, twelve, thirteen in the units Map; they need to be in a Map by themselves possibly called teens, because eleven to nineteen are pronounced differently from other numbers over ten.
I think you might need another Map with “hundred”, “thousand”, “million”, or similar in.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 26720
|
|
|
Please search this forum for threads about the meaning of the keyword static. We worry when we see so many static members in a class. There have been several other threads, all in the last week, which you would benefit from reading.
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 8428
|
|
Dishant Verma wrote:I want to enter any number having length 'n'....
You are going to have to define what the max. of 'n' is, since there is no limit to the number someone can put in. For example, I could (theorieticaly) input a number that has a thousand digits. Do you really want to be able to handle that? I'm not even sure there are words for number that big...
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 26720
|
|
|
Last time I looked in the Guiness Book of Records, they said the largest named number was the centillion, which has 601 digits.
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 3143
|
|
Campbell Ritchie wrote:Last time I looked in the Guiness Book of Records, they said the largest named number was the centillion, which has 601 digits.
Googolplex anyone?
The biggest named number that's ever actually been used for something that I've ever heard of is Graham's Number. If we try to express it in scientific notation, the number of digits in the exponent is more than the number of atoms in the universe. (I think I'm actually even grossly understating there, but it's something along those lines.)
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 8428
|
|
Campbell Ritchie wrote:Last time I looked in the Guiness Book of Records, they said the largest named number was the centillion, which has 601 digits.
Do all the numbers in between have names?
I'm pretty sure they don't all have names up to a googleplex, and this Graham's ?Number (which I had not heard of before) would be further proof you can't have names for all of them...
|
 |
Dennis Deems
Ranch Hand
Joined: Mar 12, 2011
Posts: 547
|
|
If it were me, I'd start by calling toString on the Integer. Then I'd read the String right to left a character at a time. This would require no math at all; the position of the character would tell me tens, hundreds, thousands.
But I agree completely with Campbell and Jeff: work it all out on paper first.
|
OCPJP 6
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 3143
|
|
fred rosenberger wrote:
Campbell Ritchie wrote:Last time I looked in the Guiness Book of Records, they said the largest named number was the centillion, which has 601 digits.
Do all the numbers in between have names?
I'm pretty sure they don't all have names up to a googleplex, and this Graham's ?Number (which I had not heard of before) would be further proof you can't have names for all of them...
"Graham-less-1", "Graham-less-2", ...
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 1610
|
|
Jeff Verdegan wrote:"Graham-less-1", "Graham-less-2"
I always liked the Ackermann function myself; so presumably a mathematician would allow A(G, G). I wonder if there's a Greek symbol for 'ridiculous'??
Winston
|
More computing sins are committed in the name of efficiency (without necessarily achieving it)
than for any other single reason...including blind stupidity. — W.A. Wulf
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 1610
|
|
Jeff Verdegan wrote:If we try to express it in scientific notation, the number of digits in the exponent is more than the number of atoms in the universe.
Actually, I seem to remember that when 'Googol' was named, it had something to do with the number of protons in the known universe. But now, thanks to Hubble etc, it's probably a few hundred Googol. Perhaps we should just call it a 'Hubble' and let the IAU estimate it every year for us: Jobs for the boys, no?
Winston
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 8428
|
|
Dennis Deems wrote: the position of the character would tell me tens, hundreds, thousands.
This is true, but you get into some oddities with number like "13". You don't want "13,000" to come out as "ten thousand three thousand"
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 3143
|
|
Winston Gutkowski wrote:
Jeff Verdegan wrote:"Graham-less-1", "Graham-less-2"
I always liked the Ackermann function myself; so presumably a mathematician would allow A(G, G).
http://xkcd.com/207/
Panel 3.
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 3143
|
|
fred rosenberger wrote:
Dennis Deems wrote: the position of the character would tell me tens, hundreds, thousands.
This is true, but you get into some oddities with number like "13". You don't want "13,000" to come out as "ten thousand three thousand"
That goes back to the whole "work it out on paper" bit.
"Oh, I've got it! This is actually pretty easy! (code, code, code.... test... WTF??) Okay, back to the pencil and paper to refine it for special cases..."
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 26720
|
|
|
But 13000 is the same as 13 with thousand added.
|
 |
Dishant Verma
Greenhorn
Joined: Feb 09, 2012
Posts: 25
|
|
Thanks guys for your concern.
I have done with this,with n=10 using ___?___:___
Regards:
Dishant
|
 |
 |
|
|
subject: Word Conversion
|
|
|