and, what don't you understand?

step 1: you have your number

step 2: a variable you call thouNumb = number/1000

step 3: print thouNumb " thousand"

step 4: number = number - ( thouNumb * 1000)

repeat the same steps for hundreds, .. until you have worked through the entire number

stultuske 1,092

JamesCherrill 3,702

There's a lot going on here for a beginner. Why not break it down into easy steps that you can work out one at a time:

1. Write, test and debug a version for numbers 1-19 only.

2. When that's working, enhance it to do numbers 1-99

3. When that's working, enhance it for the full range of numbers.

wallet123 15

and, what don't you understand?

step 1: you have your number

step 2: a variable you call thouNumb = number/1000

step 3: print thouNumb " thousand"

step 4: number = number - ( thouNumb * 1000)

repeat the same steps for hundreds, .. until you have worked through the entire number

theres an error saying:

main(String[])

- Type mismatch: cannot convert from

int to int

what should i do?

stultuske 1,092

what code do you have and what is the complete error?

wallet123 15

There's a lot going on here for a beginner. Why not break it down into easy steps that you can work out one at a time:

1. Write, test and debug a version for numbers 1-19 only.

2. When that's working, enhance it to do numbers 1-99

3. When that's working, enhance it for the full range of numbers.

i can do this program using "if else statement " only but cant do it using array but i have to study using array to make my work be done faster :)so im kind of..self studying :(

wallet123 15

what code do you have and what is the complete error?

i did what u said..

i did this:

```
String[] word = {"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
int[] annArray = { 20,30,40,50,60,70,80,90};
String[] tenths= {"twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety"};
int[] hundredsnum = { 100,200,300,400,500,600,700,800,900};
String [] hundredsword = {"one hundred","two hundred","three hundred","four hundred","five hundred","six hundred","seven hundred","eight hundred","nine hundred"};
int[] thounum = {1000,2000,3000,4000,5000,6000,7000,8000,9000,10000};
[B][B]thounum = number/1000;[/B][/B]
}
}
```

*Edited by peter_budo*: Keep It Clear - Do use code tags when posting any code

stultuske 1,092

you use the name thounum for an array of integers, but you try to put an integer in there. that's your error.

I already said you don't need those arrays.

JamesCherrill made an excellent point, suggesting that you should start for only the numbers one through nineteen. once you get that to work, you can continue on the rest.

wallet123 15

you use the name thounum for an array of integers, but you try to put an integer in there. that's your error.

I already said you don't need those arrays.

JamesCherrill made an excellent point, suggesting that you should start for only the numbers one through nineteen. once you get that to work, you can continue on the rest.

what arrays should i delete and what arrays should i retain?

stultuske 1,092

but, if you want to start with just one to nineteen, start with only that array.

wallet123 15

but, if you want to start with just one to nineteen, start with only that array.

u said that my mistake is when both that i used were integers..i cant understand,, if i will not use it,, then what should i use?

stultuske 1,092

no, that one mistake was, you had:

int[] thounumb = ..

and later you tried something like:

thounumb = number/1000;

so, thounumb is not an integer, it's actually an Object, an array of integers, while the result of number/1000 ís an actual integer.

you can store this result somewhere in the array, even though that's not what you want, but you can't assign that value to the array itself.

peter_budo 2,516

since I doubt you need to print "zerothousand zerohundred fourteen" when 14 is the input, I deliberately did NOT put the 0 in that array :)

and as I already said before, answering JamesCherrill, indeed, you don't need the first array, I'm aware of that, but IMHO it might be easier for the OP to see the link, and if not, all that happened is that I wrote some silly code :)

Even though there is no need for zero due to assignment requirement "1-10,001" it is much easier to have it included as to play games with increment of 1 in my opinion...

wallet123 15

no, that one mistake was, you had:

int[] thounumb = ..

and later you tried something like:

thounumb = number/1000;so, thounumb is not an integer, it's actually an Object, an array of integers, while the result of number/1000 ís an actual integer.

you can store this result somewhere in the array, even though that's not what you want, but you can't assign that value to the array itself.

does that mean that i will have to create another variable?

JeffGrigg 170

To successfully complete an assignment like this, you need to be able to break it down into smaller problems. You need to be able to recognize patterns in the inputs and outputs you want, and use those patterns to simplify the code.

In this assignment, you also need to know how to use integer division (the '/' operator) and the modulo or remainder operator ('%') to separate a big number down into its component parts.

I would write multiple methods (functions) to break this problem down into smaller problems that are easier to solve.

You don't need to use arrays. You can use "if" statements instead. But your program will be longer and more tedious.

Let's start here: If you only had to write a method that took a number between 1 and 19, and returned the words "one" through "nineteen", could you do it? (If so, go ahead and do it.)

Consider the numbers 20 through 29. The results for these are "twenty", "twenty one", "twenty two", "twenty three", etc... up to "twenty nine". Notice the pattern: "twenty one" through "twenty nine" starts with the word "twenty", adds a space, and then uses one of the words "one" through "nine". Could you use the method suggested above to handle the range of "one" through "nine"? If you could use division to isolate the "tens digit", then you could handle the "twenty" range, the "thirty" range, etc... all the way up to "ninety nine".

Notice that there's a pattern to hundreds, too: "one hundred", "two hundred", "three hundred", etc... up to "nine hundred". If you could isolate the "hundreds digit", you could use the first method above to come up with a word for it. Then add the word " hundred". And then deal with the last two digits.

The same "trick" would work for thousands. And once you get that far, the program is complete.

DavidKroukamp 105

*Edited by peter_budo*: Keep It Spam-Free - Do not post any affiliate links or links to off-site ecommerce sites or auctions

stultuske 1,092

the point is to give the OP everything he/she needs (to know) to complete the assignment themselves, which is what we did.

DavidKroukamp 105

the point is to give the OP everything he/she needs (to know) to complete the assignment themselves, which is what we did.

its not complete code? he/she still has to understand it and it only goes up to 100? also i found that on a simple google search? 'convert number to words java'

*Edited by DavidKroukamp*: n/a

stultuske 1,092

with a little adaptations you can do without understanding the code, it would be the entire code. also, technically, AFAIK, there was no need to understand it, the OP needed to hand it in as the solution of the assignment, and unfortunately, a lot of beginners won't force themselves to understand it, if the solution is given.

nothing stopped the OP from Googling that query, if it had been googled, it would have propably been solved a lot sooner (don't really know if it got solved now)

DavidKroukamp 105

with a little adaptations you can do without understanding the code, it would be the entire code. also, technically, AFAIK, there was no need to understand it, the OP needed to hand it in as the solution of the assignment, and unfortunately, a lot of beginners won't force themselves to understand it, if the solution is given.

nothing stopped the OP from Googling that query, if it had been googled, it would have propably been solved a lot sooner (don't really know if it got solved now)

agreed, sorry

stultuske 1,092

DavidKroukamp 105

Hehe ;). must be my lucky day!

wallet123 15

To successfully complete an assignment like this, you need to be able to break it down into smaller problems. You need to be able to recognize patterns in the inputs and outputs you want, and use those patterns to simplify the code.

In this assignment, you also need to know how to use integer division (the '/' operator) and the modulo or remainder operator ('%') to separate a big number down into its component parts.

I would write multiple methods (functions) to break this problem down into smaller problems that are easier to solve.

You don't need to use arrays. You can use "if" statements instead. But your program will be longer and more tedious.

Let's start here: If you only had to write a method that took a number between 1 and 19, and returned the words "one" through "nineteen", could you do it? (If so, go ahead and do it.)

Consider the numbers 20 through 29. The results for these are "twenty", "twenty one", "twenty two", "twenty three", etc... up to "twenty nine". Notice the pattern: "twenty one" through "twenty nine" starts with the word "twenty", adds a space, and then uses one of the words "one" through "nine". Could you use the method suggested above to handle the range of "one" through "nine"? If you could use division to isolate the "tens digit", then you could handle the "twenty" range, the "thirty" range, etc... all the way up to "ninety nine".

Notice that there's a pattern to hundreds, too: "one hundred", "two hundred", "three hundred", etc... up to "nine hundred". If you could isolate the "hundreds digit", you could use the first method above to come up with a word for it. Then add the word " hundred". And then deal with the last two digits.

The same "trick" would work for thousands. And once you get that far, the program is complete.

here's the code that i did:

```
package now;
import javax.swing.JOptionPane;
public class Rabbit {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String thousand = "";
String hundred ="";
String ten="";
String teen="";
int enter= Integer.parseInt(JOptionPane.showInputDialog( null,"Enter number here:"));
int libo = enter / 1000;
int dalawalibo = enter % 1000;
int tatlolibo= libo * 1000;
int daan = dalawalibo / 100;
int dalawadaan = dalawalibo % 100;
int tatlodaan= daan * 100;
int nine1 = dalawadaan / 19;
int nine2= nine1 * 19;
int nine3 = dalawadaan % 19;
int eight1 = nine3 / 18;
int eight2= eight1 * 18;
int eight3 = nine3 % 18;
int seven1 = eight3 / 17;
int seven2= seven1 * 17;
int seven3 = eight3 %17;
int six1 = seven3 / 16;
int six2 = six1 * 16;
int six3= seven3 % 16;
int five1 = six3 / 15;
int five2 = five1 * 15;
int five3 = six3 % 15;
int four1 = five3 / 14;
int four2 = four1 * 14;
int four3= five3 % 14;
int three1 = four3 / 13;
int three2 = three1 * 13;
int three3= four3 %13;
int two1 = three3 / 12;
int two2 = two1 * 12;
int two3= three3 % 12;
int one1 = two3 / 11;
int one2 = one1 * 11;
int one3= two3 % 11;
int tenna = one3 / 10;
int tenne = tenna * 10;
int tenni= dalawadaan % 10;
int isa1 = tenni / 1;
int isa2 = isa1 * 1;
if(isa2 == 9)
{
teen ="Nine";
}
else if(isa2 == 8)
{
teen = "Eight";
}
else if(isa2 == 7)
{
teen = "Seven";
}
else if(isa2 == 6)
{
teen= "Six";
}
else if(isa2 == 5)
{
teen= "Five";
}
else if(isa2 == 4)
{
teen = "Four";
}
else if(isa2 == 3)
{
teen = "Three";
}
else if(isa2 == 2)
{
teen = "Two";
}
else if(isa2 == 1)
{
teen= "One";
}
{
if(nine2 == 19)
{
teen = "Nineteen";
}
else if(eight2 == 18)
{teen = "Eighteen"
;}
else if(seven2 == 17)
{
teen = "Seventeen";
}
else if(six2 == 16)
{
teen = "Sixteen";
}
else if(five2 == 15)
{
teen = "Fifteen";
}
else if(four2 == 14)
{
teen = "Fourteen";
}
else if(three2 == 13)
{
teen = "Thirteen";
}
else if(two2 == 12)
{
teen = "Twelve";
}
else if(one2 == 11)
{
teen = "eleven";
}
{
if(tenne == 90)
{
ten = "Ninety";
}
else if(tenne == 80)
{ten = "Eighty"
;}
else if(tenne == 70)
{
ten = "Seventy";
}
else if(tenne == 60)
{
ten = "Sixty";
}
else if(tenne == 50)
{
ten = "Fifty";
}
else if(tenne == 40)
{
ten = "Fourty";
}
else if(tenne == 30)
{
ten = "Thirty";
}
else if(tenne == 20)
{
ten = "Twenty";
}
else if(tenne == 10)
{
ten = "Ten";
}
}
if(tatlodaan == 900)
{
hundred = "Nine Hundred";
}
else if( tatlodaan== 800)
{
hundred= "Eight Hundred";
}
else if(tatlodaan == 700)
{
hundred = "Seven hundred";
}
else if(tatlodaan == 600)
{
hundred ="Six Hundred";
}
else if(tatlodaan == 500)
{
hundred ="Five Hundred";
}
else if(tatlodaan == 400)
{
hundred ="Four Hundred";
}
else if(tatlodaan == 300)
{
hundred ="Three Hundred";
}
else if(tatlodaan == 200)
{
hundred ="Two Hundred";
}
else if(tatlodaan == 100)
{
hundred="One Hundred"
;}
if(tatlolibo == 10000)
{
thousand= "Ten Thousand";
}
else if(tatlolibo == 9000)
{
thousand = "Nine Thousand";
}
else if(tatlolibo == 8000)
{
thousand = "Eight Thousand"
;}
else if(tatlolibo == 7000)
{
thousand = "Seven Thousand";
}
else if(tatlolibo == 6000)
{
thousand = "Six Thousand";
}
else if(tatlolibo == 5000)
{
thousand = "Five Thousand";
}
else if(tatlolibo == 4000)
{
thousand= "Four Thousand";
}
else if(tatlolibo == 3000)
{
thousand = "Three Thousand";
}
else if(tatlolibo == 2000)
{
thousand= "Two Thousand";
}
else if(tatlolibo == 1000)
{
thousand = "One Thousand";
}
JOptionPane.showMessageDialog(null,thousand+" "+hundred+" "+ten+" "+teen);
}
}}
```

but there seems to be an error when i run it because the words that comes out are wrong..i cant identify my error!

*Edited by peter_budo*: Correcting closing code tag

stultuske 1,092

what do you enter as value, what do you expect as a result, and what do you get?

The code you posted might work a bit, but it's ... well, a bit of a mess.

if you want to 'debug' your code (without actually debugging, that is :) ) add print statements, that print the values of your key-variables during the running of the application, to check whether they actually contain what you think they contain.

also, have you tried to write what we suggested?

it's a lot less code, and thus easier to maintain and check for errors, for that much

JeffGrigg 170

Your code has a number of good ideas. Dividing by numbers between 19 and 11, however, is just a bad idea.

If you could figure out the pattern with twentys, thirtys, fourtys, ...etc... ninetys -- then you'd have a working program. Focus on this question: What's the best way to handle numbers in the range from 20 to 99?

wallet123 15

Your code has a number of good ideas. Dividing by numbers between 19 and 11, however, is just a bad idea.

If you could figure out the pattern with twentys, thirtys, fourtys, ...etc... ninetys -- then you'd have a working program. Focus on this question: What's the best way to handle numbers in the range from 20 to 99?

yeah ur right! thats my problem, cant find the right thing to do so that when i input numbers 20-99 , the correct word will come out..ive been doing this for days but i raelly cant figure out how to fix my error :(

stultuske 1,092

twenty one, twenty two, ... , twenty nine, thirty,

thirty one, thirty two, ... , thirty nine, fourty,

fourty one, fourty two, ... , fourty nine, fifty,

...

JeffGrigg 170

..., cant find the right thing to do so that when i input numbers 20-99 , the correct word will come out..ive been doing this for days but i raelly cant figure out how to fix my error :(

If you had a number in the range of 20 to 99, and you divided it by ten, what would you get?

(Try it with a few numbers in that range, if you're not sure. ;-)

wallet123 15

If you had a number in the range of 20 to 99, and you divided it by ten, what would you get?

(Try it with a few numbers in that range, if you're not sure. ;-)

i will get a negative answer so does that mean that i would have to divide it by one hundred instead of ten?

JeffGrigg 170

i will get a negative answer so does that mean that i would have to divide it by one hundred instead of ten?

When I take the number 32 and divide by 10, I get 3.

3 is a positive number, not a negative number.

wallet123 15

When I take the number 32 and divide by 10, I get 3.

3 is a positive number, not a negative number.

im sorry, i still dont get it :(