This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.

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

preeti dengri
Ranch Hand

Joined: Nov 30, 2000
Posts: 111

posted

0

thanks Sean for putting me on the right track preeti

Hi 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]