Results 1 to 13 of 13
Thread: Java question
- 11-24-2009, 01:55 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 32
- Rep Power
- 0
Java question
Hello,
I'm new to the JAVA programming world and I have a few question.
I want to make a program that translates numbers in words.
Example:
You typ in: 580
It comes out in words: five hundred eighty
My question is how to split these numbers, because I have an array filled with numbers comes from the words. But I have to make JAVA split 580 in 500 and 80, or a 5 and 8 because in the array it is saved as those numbers...
- 11-24-2009, 02:01 PM #2
Threre are different possibilities (as usual). If 580 is a String you can use the split() or subString() methods to get the single digits. If it's an int you can hack around with modulo(%) and integer division.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 11-24-2009, 02:03 PM #3
Member
- Join Date
- Nov 2009
- Posts
- 32
- Rep Power
- 0
Yes, it is a String...
Can you tell me how the Split or the Substring work in this case?
- 11-24-2009, 02:04 PM #4
What part of the API doc didn't you understand?
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 11-24-2009, 02:05 PM #5
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
- 11-24-2009, 02:06 PM #6
Member
- Join Date
- Nov 2009
- Posts
- 32
- Rep Power
- 0
Well, how to do it in this case, I think that te API documents is very confusing for beginners..
- 11-24-2009, 02:06 PM #7
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 11-24-2009, 02:07 PM #8
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 11-24-2009, 02:10 PM #9
Member
- Join Date
- Nov 2009
- Posts
- 32
- Rep Power
- 0
OK,
I have everythinking accept for the actionPerformed.
First I thought that Integer.parseInt could work but then I got stuck at the array point, I couldnt get the Integer get split.
Now I wanted to work with the Substring, but I haven't got any Idea how to do it, because if I want to get the numbers working with the array's you must get integers back right.
Here is some of my code:
String[] klein = {"nul", "een", "twee", "drie", "vier", "vijf", "zes", "zeven", "acht", "negen", "tien", "elf", "twaalf", "dertien", "veertien", "vijftien", "zestien", "zeventien", "achttien", "negentien"};
String[] groot = {"nul", "tien", "twintig", "dertig", "veertig", "vijftig", "zestig", "zeventig", "tachtig", "negentig"};
public void actionPerformed(ActionEvent e)
{
int nr = Integer.parseInt(invoerVeld.getText());
if(nr<100)
{
//?????? must split my Integer at this point
//88 for example is groot[8] and klein[8]
if(nr<20)
{
uitvoerVeld.setText(klein[nr]);
}
}
}
I get stuck at the ActionPerformed method...Last edited by TGH; 11-24-2009 at 02:19 PM.
- 11-24-2009, 02:26 PM #10
ok, so you've got an integer:
Something like that, it's untested.Java Code:int k = 0; int g = 0; if(nr<20) { uitvoerVeld.setText(klein[nr]); }else{ k = nr%10; g = (nr - k)/10; uitvoerVeld.setText(groot[g] + klein[k]); }Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 11-24-2009, 02:33 PM #11
Member
- Join Date
- Nov 2009
- Posts
- 32
- Rep Power
- 0
Yes, Thank you
I can work futher with this assignment, Its stupid that I didn't saw that earlier.
- 11-27-2009, 12:13 PM #12
Member
- Join Date
- Nov 2009
- Posts
- 32
- Rep Power
- 0
I have a new question,
How can you put more buttons in the BorderLayout"?
I want to put three buttons there, one to make something smaller, a button that makes that something go down and a button to make it bigger...
How can I do it?
(Now I only get 1 button, bigger or smaller or the 'go down' button...)
- 11-27-2009, 02:05 PM #13
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Java Question Bank
By mgm2010 in forum New To JavaReplies: 2Last Post: 07-31-2009, 06:45 PM -
question about java rmi
By hakimade in forum Advanced JavaReplies: 1Last Post: 07-01-2009, 07:15 AM -
Java Architecture Question
By ronakppatel in forum Web FrameworksReplies: 1Last Post: 10-01-2008, 12:13 PM -
Question regarding Java Certification
By Ms.Ranjan in forum New To JavaReplies: 11Last Post: 06-25-2008, 04:37 AM -
Java Question
By Jay-1.1 in forum New To JavaReplies: 11Last Post: 05-01-2008, 04:04 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks