Hi guys i am new here
i want to help about:
how to convert digit(number) into word
for example:
Enter a number:123
Output:one two three

Recommended Answers

All 21 Replies

There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in doing your homework for you.

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"

Post what you have done so far and someone will help you from there.

Start by working out the logic in ordinary English forget the Java for now.
Write down a few numbers, work out the correct answers, write doen how you did that. Then translate that into Java.

this program
solve by array or for loops

String a[] = {"Zero","One", "Two", "Three", "Four", "Five", "Six" , "Seven","Eight","Nine"};

That's a good start. Given the irregular pattern for the teens it nay be worth carrying on with that up to 19

and, depending on how far it must go, add logic for thousands and hundreds.
it's not at all difficut to implement, if you just want:
to be translated into
two one three
you can just print the elements of the array you already have by using the numbers-to-translate as indices.
if you need to go for more correct numbers, you'll have to add some conditional statements and different arrays, but it isn't much more difficult.

this program without hundred and thousand jusd red simple numbers . and this program too much difficult .also i try alot to solve ..
please help me .

import java.util.*;
class word_num
  public static void main (String [] args)
     int x,i;
     String m="\t";
     System.outprintln("Enter number");
     Scanner ip =new Scanner(System.in);
     for (i=1; i<=3; i++)
        else if (x==0)
        else if (x==2)
        else if (x==3)
        else if (x==4)
        else if (x==5)
        else if (x==6)
        else if (x==7)
        else if (x==8)
        else if (x==9)


ehm .. if you don't need to take into account hundreds/thousands, I 've told you in my previous reply how to solve it, using the array you have, and with a lot less code than this.

don't ignore answers, go through them and ask about them if you don't understand them.

thanks for answer
I am realy dont know how to use array in this program

import java.util.*;
class word_num
  public static void main (String[] args)
     int k,rev,k1;
     int b;
     Scanner sc=new Scanner(System.in);
     System.out.println("Enter any integer Numbers");
     case 0:
     System.out.println("zero"); break;
     case 1:
     System.out.println("one"); break;
     case 2:
     System.out.println("two"); break;
     case 3:
     System.out.println("three"); break;
     case 4:
     System.out.println("four"); break;
     case 5:
     System.out.println("five"); break;
     case 6:
     System.out.println("six"); break;
     case 7:
     System.out.println("seven"); break;
     case 8:
     System.out.println("eight"); break;
     case 9:
     System.out.println("nine"); break;

The switch is OK, but the array was better. Here's how it works:
If you have your array as before

String a[] = {"Zero","One", "Two", "Three", "Four", "Five", "Six" , "Seven","Eight","Nine"};

a[0] is "Zero"
a[1] is "One"
so if you have an int b with values 0-9 then a[b] is the corresponding string.

how I can int b with values 0-9 (i use array)

i understand this point ^^

i try this program

import java.util.*;
class word_num
  public static void main (String[] args)
     int b; 
     String a[] = {"Zero","One", "Two", "Three", "Four", "Five", "Six" , "Seven","Eight","Nine"};
     Scanner sc=new Scanner(System.in);
     System.out.println("Enter any integer Numbers");


it is work , but it read just one number not more
like 7 7 seven
83 eight

In your previous (switch) program you had a loop that was doing /10 and %10 calculations to get each of the digits in turn. You still need a loop with something like that to get each of the digits.

like this

for(b=1; b<=10; b++)

like this

for(b=1; b<=10; b++)

No. Go back and look at your pervious code - I didn't read it all but it looks like it was doing the right kind of stuff

(ps - its dinner time here in France, I'm offline until tomorrow. Good luck. J)

thanks for all answers
have nice dinner ^_^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.