Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Everett James   on Sep 23 In Java Category.

  
Question Answered By: Salvador Alexander   on Sep 23

Here is another way to do it.(recursive way(shorter) or you can do it without
recursive(long))

this is a recursive method

static i = 0;
public static void convert(int num)
{
if (num < 10)
{ switch num
{
case 1: System.out.print("one"); break;
case 2: .......................
........................case 9 :
}
switch i
{ case 1: System.out.print("tens"); break;
case 2: System.out.print("hundreds"); break;
................
}
else
{ i++
convert(num / 10);
switch (num%10) {
case 1: System.out.print("one"); break;
case 2: .......................
........................case 9 :
}
}
}
you can keep track of the position of the number to determine (thousand,
hundred....)

you can use double  as parameter but you should treat it in slightly different
way
I hope you will help you.

Share: 

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


Tagged: