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.

"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.?"

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.

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: 41006

28

posted

0

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.

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...

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 41006

28

posted

0

Last time I looked in the Guiness Book of Records, they said the largest named number was the centillion, which has 601 digits.

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.)

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...

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.

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...

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?

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..."

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...

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.

Sorry for bumping this topic, but... I am currently playing with a non-Java based tool, remembered this topic, and wondered if I can configure it to do this very task. And of course, to tackle that thousand digit number.

Anyway, according to my testing, this thousand digit number ...

one duotrigintatrecentillion two hundred and thirty four untrigintatrecentillion five hundred and sixty seven trigintatrecentillion eight hundred and ninety novemvigintitrecentillion one hundred and twenty three octovigintitrecentillion four hundred and fifty six septemvigintitrecentillion seven hundred and eighty nine sesvigintitrecentillion twelve quinquavigintitrecentillion three hundred and forty five quattuorvigintitrecentillion six hundred and seventy eight tresvigintitrecentillion nine hundred and one duovigintitrecentillion two hundred and thirty four unvigintitrecentillion five hundred and sixty seven vigintitrecentillion eight hundred and ninety novendecitrecentillion one hundred and twenty three octodecitrecentillion four hundred and fifty six septendecitrecentillion seven hundred and eighty nine sedecitrecentillion twelve quinquadecitrecentillion three hundred and forty five quattuordecitrecentillion six hundred and seventy eight tredecitrecentillion nine hundred and one duodecitrecentillion two hundred and thirty four undecitrecentillion five hundred and sixty seven decitrecentillion eight hundred and ninety noventrecentillion one hundred and twenty three octotrecentillion four hundred and fifty six septentrecentillion seven hundred and eighty nine sestrecentillion twelve quinquatrecentillion three hundred and forty five quattuortrecentillion six hundred and seventy eight trestrecentillion nine hundred and one duotrecentillion two hundred and thirty four untrecentillion five hundred and sixty seven trecentillion eight hundred and ninety novenonagintaducentillion one hundred and twenty three octononagintaducentillion four hundred and fifty six septenonagintaducentillion seven hundred and eighty nine senonagintaducentillion twelve quinquanonagintaducentillion three hundred and forty five quattuornonagintaducentillion six hundred and seventy eight trenonagintaducentillion nine hundred and one duononagintaducentillion two hundred and thirty four unnonagintaducentillion five hundred and sixty seven nonagintaducentillion eight hundred and ninety novemoctogintaducentillion one hundred and twenty three octooctogintaducentillion four hundred and fifty six septemoctogintaducentillion seven hundred and eighty nine sexoctogintaducentillion twelve quinquaoctogintaducentillion three hundred and forty five quattuoroctogintaducentillion six hundred and seventy eight tresoctogintaducentillion nine hundred and one duooctogintaducentillion two hundred and thirty four unoctogintaducentillion five hundred and sixty seven octogintaducentillion eight hundred and ninety novenseptuagintaducentillion one hundred and twenty three octoseptuagintaducentillion four hundred and fifty six septenseptuagintaducentillion seven hundred and eighty nine seseptuagintaducentillion twelve quinquaseptuagintaducentillion three hundred and forty five quattuorseptuagintaducentillion six hundred and seventy eight treseptuagintaducentillion nine hundred and one duoseptuagintaducentillion two hundred and thirty four unseptuagintaducentillion five hundred and sixty seven septuagintaducentillion eight hundred and ninety novensexagintaducentillion one hundred and twenty three octosexagintaducentillion four hundred and fifty six septensexagintaducentillion seven hundred and eighty nine sesexagintaducentillion twelve quinquasexagintaducentillion three hundred and forty five quattuorsexagintaducentillion six hundred and seventy eight tresexagintaducentillion nine hundred and one duosexagintaducentillion two hundred and thirty four unsexagintaducentillion five hundred and sixty seven sexagintaducentillion eight hundred and ninety novenquinquagintaducentillion one hundred and twenty three octoquinquagintaducentillion four hundred and fifty six septenquinquagintaducentillion seven hundred and eighty nine sesquinquagintaducentillion twelve quinquaquinquagintaducentillion three hundred and forty five quattuorquinquagintaducentillion six hundred and seventy eight tresquinquagintaducentillion nine hundred and one duoquinquagintaducentillion two hundred and thirty four unquinquagintaducentillion five hundred and sixty seven quinquagintaducentillion eight hundred and ninety novenquadragintaducentillion one hundred and twenty three octoquadragintaducentillion four hundred and fifty six septenquadragintaducentillion seven hundred and eighty nine sesquadragintaducentillion twelve quinquaquadragintaducentillion three hundred and forty five quattuorquadragintaducentillion six hundred and seventy eight tresquadragintaducentillion nine hundred and one duoquadragintaducentillion two hundred and thirty four unquadragintaducentillion five hundred and sixty seven quadragintaducentillion eight hundred and ninety noventrigintaducentillion one hundred and twenty three octotrigintaducentillion four hundred and fifty six septentrigintaducentillion seven hundred and eighty nine sestrigintaducentillion twelve quinquatrigintaducentillion three hundred and forty five quattuortrigintaducentillion six hundred and seventy eight trestrigintaducentillion nine hundred and one duotrigintaducentillion two hundred and thirty four untrigintaducentillion five hundred and sixty seven trigintaducentillion eight hundred and ninety novemvigintiducentillion one hundred and twenty three octovigintiducentillion four hundred and fifty six septemvigintiducentillion seven hundred and eighty nine sesvigintiducentillion twelve quinquavigintiducentillion three hundred and forty five quattuorvigintiducentillion six hundred and seventy eight tresvigintiducentillion nine hundred and one duovigintiducentillion two hundred and thirty four unvigintiducentillion five hundred and sixty seven vigintiducentillion eight hundred and ninety novendeciducentillion one hundred and twenty three octodeciducentillion four hundred and fifty six septendeciducentillion seven hundred and eighty nine sedeciducentillion twelve quinquadeciducentillion three hundred and forty five quattuordeciducentillion six hundred and seventy eight tredeciducentillion nine hundred and one duodeciducentillion two hundred and thirty four undeciducentillion five hundred and sixty seven deciducentillion eight hundred and ninety novenducentillion one hundred and twenty three octoducentillion four hundred and fifty six septenducentillion seven hundred and eighty nine seducentillion twelve quinquaducentillion three hundred and forty five quattuorducentillion six hundred and seventy eight treducentillion nine hundred and one duoducentillion two hundred and thirty four unducentillion five hundred and sixty seven ducentillion eight hundred and ninety novenonagintacentillion one hundred and twenty three octononagintacentillion four hundred and fifty six septenonagintacentillion seven hundred and eighty nine senonagintacentillion twelve quinquanonagintacentillion three hundred and forty five quattuornonagintacentillion six hundred and seventy eight trenonagintacentillion nine hundred and one duononagintacentillion two hundred and thirty four unnonagintacentillion five hundred and sixty seven nonagintacentillion eight hundred and ninety novemoctogintacentillion one hundred and twenty three octooctogintacentillion four hundred and fifty six septemoctogintacentillion seven hundred and eighty nine sexoctogintacentillion twelve quinquaoctogintacentillion three hundred and forty five quattuoroctogintacentillion six hundred and seventy eight tresoctogintacentillion nine hundred and one duooctogintacentillion two hundred and thirty four unoctogintacentillion five hundred and sixty seven octogintacentillion eight hundred and ninety novenseptuagintacentillion one hundred and twenty three octoseptuagintacentillion four hundred and fifty six septenseptuagintacentillion seven hundred and eighty nine seseptuagintacentillion twelve quinquaseptuagintacentillion three hundred and forty five quattuorseptuagintacentillion six hundred and seventy eight treseptuagintacentillion nine hundred and one duoseptuagintacentillion two hundred and thirty four unseptuagintacentillion five hundred and sixty seven septuagintacentillion eight hundred and ninety novensexagintacentillion one hundred and twenty three octosexagintacentillion four hundred and fifty six septensexagintacentillion seven hundred and eighty nine sesexagintacentillion twelve quinquasexagintacentillion three hundred and forty five quattuorsexagintacentillion six hundred and seventy eight tresexagintacentillion nine hundred and one duosexagintacentillion two hundred and thirty four unsexagintacentillion five hundred and sixty seven sexagintacentillion eight hundred and ninety novenquinquagintacentillion one hundred and twenty three octoquinquagintacentillion four hundred and fifty six septenquinquagintacentillion seven hundred and eighty nine sesquinquagintacentillion twelve quinquaquinquagintacentillion three hundred and forty five quattuorquinquagintacentillion six hundred and seventy eight tresquinquagintacentillion nine hundred and one duoquinquagintacentillion two hundred and thirty four unquinquagintacentillion five hundred and sixty seven quinquagintacentillion eight hundred and ninety novenquadragintacentillion one hundred and twenty three octoquadragintacentillion four hundred and fifty six septenquadragintacentillion seven hundred and eighty nine sesquadragintacentillion twelve quinquaquadragintacentillion three hundred and forty five quattuorquadragintacentillion six hundred and seventy eight tresquadragintacentillion nine hundred and one duoquadragintacentillion two hundred and thirty four unquadragintacentillion five hundred and sixty seven quadragintacentillion eight hundred and ninety noventrigintacentillion one hundred and twenty three octotrigintacentillion four hundred and fifty six septentrigintacentillion seven hundred and eighty nine sestrigintacentillion twelve quinquatrigintacentillion three hundred and forty five quattuortrigintacentillion six hundred and seventy eight trestrigintacentillion nine hundred and one duotrigintacentillion two hundred and thirty four untrigintacentillion five hundred and sixty seven trigintacentillion eight hundred and ninety novemviginticentillion one hundred and twenty three octoviginticentillion four hundred and fifty six septemviginticentillion seven hundred and eighty nine sesviginticentillion twelve quinquaviginticentillion three hundred and forty five quattuorviginticentillion six hundred and seventy eight tresviginticentillion nine hundred and one duoviginticentillion two hundred and thirty four unviginticentillion five hundred and sixty seven viginticentillion eight hundred and ninety novendecicentillion one hundred and twenty three octodecicentillion four hundred and fifty six septendecicentillion seven hundred and eighty nine sedecicentillion twelve quinquadecicentillion three hundred and forty five quattuordecicentillion six hundred and seventy eight tredecicentillion nine hundred and one duodecicentillion two hundred and thirty four undecicentillion five hundred and sixty seven decicentillion eight hundred and ninety novencentillion one hundred and twenty three octocentillion four hundred and fifty six septencentillion seven hundred and eighty nine sexcentillion twelve quinquacentillion three hundred and forty five quattuorcentillion six hundred and seventy eight trescentillion nine hundred and one duocentillion two hundred and thirty four uncentillion five hundred and sixty seven centillion eight hundred and ninety novenonagintillion one hundred and twenty three octononagintillion four hundred and fifty six septenonagintillion seven hundred and eighty nine senonagintillion twelve quinquanonagintillion three hundred and forty five quattuornonagintillion six hundred and seventy eight trenonagintillion nine hundred and one duononagintillion two hundred and thirty four unnonagintillion five hundred and sixty seven nonagintillion eight hundred and ninety novemoctogintillion one hundred and twenty three octooctogintillion four hundred and fifty six septemoctogintillion seven hundred and eighty nine sexoctogintillion twelve quinquaoctogintillion three hundred and forty five quattuoroctogintillion six hundred and seventy eight tresoctogintillion nine hundred and one duooctogintillion two hundred and thirty four unoctogintillion five hundred and sixty seven octogintillion eight hundred and ninety novenseptuagintillion one hundred and twenty three octoseptuagintillion four hundred and fifty six septenseptuagintillion seven hundred and eighty nine seseptuagintillion twelve quinquaseptuagintillion three hundred and forty five quattuorseptuagintillion six hundred and seventy eight treseptuagintillion nine hundred and one duoseptuagintillion two hundred and thirty four unseptuagintillion five hundred and sixty seven septuagintillion eight hundred and ninety novensexagintillion one hundred and twenty three octosexagintillion four hundred and fifty six septensexagintillion seven hundred and eighty nine sesexagintillion twelve quinquasexagintillion three hundred and forty five quattuorsexagintillion six hundred and seventy eight tresexagintillion nine hundred and one duosexagintillion two hundred and thirty four unsexagintillion five hundred and sixty seven sexagintillion eight hundred and ninety novenquinquagintillion one hundred and twenty three octoquinquagintillion four hundred and fifty six septenquinquagintillion seven hundred and eighty nine sesquinquagintillion twelve quinquaquinquagintillion three hundred and forty five quattuorquinquagintillion six hundred and seventy eight tresquinquagintillion nine hundred and one duoquinquagintillion two hundred and thirty four unquinquagintillion five hundred and sixty seven quinquagintillion eight hundred and ninety novenquadragintillion one hundred and twenty three octoquadragintillion four hundred and fifty six septenquadragintillion seven hundred and eighty nine sesquadragintillion twelve quinquaquadragintillion three hundred and forty five quattuorquadragintillion six hundred and seventy eight tresquadragintillion nine hundred and one duoquadragintillion two hundred and thirty four unquadragintillion five hundred and sixty seven quadragintillion eight hundred and ninety noventrigintillion one hundred and twenty three octotrigintillion four hundred and fifty six septentrigintillion seven hundred and eighty nine sestrigintillion twelve quinquatrigintillion three hundred and forty five quattuortrigintillion six hundred and seventy eight trestrigintillion nine hundred and one duotrigintillion two hundred and thirty four untrigintillion five hundred and sixty seven trigintillion eight hundred and ninety novemvigintillion one hundred and twenty three octovigintillion four hundred and fifty six septemvigintillion seven hundred and eighty nine sesvigintillion twelve quinquavigintillion three hundred and forty five quattuorvigintillion six hundred and seventy eight tresvigintillion nine hundred and one duovigintillion two hundred and thirty four unvigintillion five hundred and sixty seven vigintillion eight hundred and ninety novendecillion one hundred and twenty three octodecillion four hundred and fifty six septendecillion seven hundred and eighty nine sedecillion twelve quinquadecillion three hundred and forty five quattuordecillion six hundred and seventy eight tredecillion nine hundred and one duodecillion two hundred and thirty four undecillion five hundred and sixty seven decillion eight hundred and ninety nonillion one hundred and twenty three octillion four hundred and fifty six septillion seven hundred and eighty nine sextillion twelve quintillion three hundred and forty five quadrillion six hundred and seventy eight trillion nine hundred and one billion two hundred and thirty four million five hundred and sixty seven thousand eight hundred and ninety

Technically, a "Googol" is not a useable number for this... why? A googol is 10^100 which is not needed as only every three digits need a name. The names around the googol are "duotrigintillion" (which is 10^99), and "trestrigintillion" (which is 10^102).

As for "Googolplex", which is ten to the googol, that too, is not a useable number -- as a googol is also not divisable by three (and kudos to those who knows how I was able to determine that in my head ).

Campbell Ritchie wrote:I know how to prove that technique works, too.

It is amazing, IMO, of the stuff that people learn while in grade school, that you think that you will never use ever -- and then, thirty years later, you remember it, and use it !!

Henry Wong wrote:It is amazing, IMO, of the stuff that people learn while in grade school, that you think that you will never use ever -- and then, thirty years later, you remember it, and use it !!

Kindergarten. All the important stuff in life, you learn in kindergarten.

Meghana Reddy wrote:Just curious, Why bother about a 1000 digit number when java has a max value for Long which is 9223372036854775807 and is only 19 digits.

Meghana Reddy wrote:Just curious, Why bother about a 1000 digit number when java has a max value for Long which is 9223372036854775807 and is only 19 digits.

Meghana Reddy wrote:Thanks Jeff. I never have had to use it before.

Also, you should distinguish between a requirement and implementation detail. There is nothing in the requirement that says that there is a limit to the size.... Of course, one of the requirements was to use Java -- which I didn't do...