# string display

preeti dengri

Ranch Hand

Posts: 111

Sean MacLean

author

Ranch Hand

Ranch Hand

Posts: 621

posted 15 years ago

Preeti,

Since this looks an aweful lot like a question in the JavaRanch CattleDrive, I'll only give you bits of the code to do this. So here it goes. There is no built in facility in Java to do this type of conversion. You have to do it by 'hand'. The simplest way is to use the / division and % (mod) operators to determine the rank of the numbers. For instance,

int deci = 22 / 10; // equals 2 because it's integer division

and then

int uni = 22 % 10; // equals 2 because that's the remainder

Now set up two arrays like this,

and get the String representation as such,

String result = deciStrings[deci] + "-" + uniStrings[uni+1];

Of course, you have to derive the logic to make this handle any number. Hope this helps.

Sean

Since this looks an aweful lot like a question in the JavaRanch CattleDrive, I'll only give you bits of the code to do this. So here it goes. There is no built in facility in Java to do this type of conversion. You have to do it by 'hand'. The simplest way is to use the / division and % (mod) operators to determine the rank of the numbers. For instance,

int deci = 22 / 10; // equals 2 because it's integer division

and then

int uni = 22 % 10; // equals 2 because that's the remainder

Now set up two arrays like this,

and get the String representation as such,

String result = deciStrings[deci] + "-" + uniStrings[uni+1];

Of course, you have to derive the logic to make this handle any number. Hope this helps.

Sean

preeti dengri

Ranch Hand

Posts: 111

Harish Babu.N

Greenhorn

Posts: 11

posted 15 years ago

Hi

Bug in u'r code

Use

String result = deciStrings[deci-1] + "-" + uniStrings[uni];

Bug in u'r code

Use

String result = deciStrings[deci-1] + "-" + uniStrings[uni];

Originally posted by Sean MacLean:

[B]Preeti,

Since this looks an aweful lot like a question in the JavaRanch CattleDrive, I'll only give you bits of the code to do this. So here it goes. There is no built in facility in Java to do this type of conversion. You have to do it by 'hand'. The simplest way is to use the / division and % (mod) operators to determine the rank of the numbers. For instance,

int deci = 22 / 10; // equals 2 because it's integer division

and then

int uni = 22 % 10; // equals 2 because that's the remainder

Now set up two arrays like this,

and get the String representation as such,

String result = deciStrings[deci] + "-" + uniStrings[uni+1];

Of course, you have to derive the logic to make this handle any number. Hope this helps.

Sean[/B]