|
|
#1 (permalink) |
|
Silver Member
![]() Join Date: Aug 2006
Location: New Zealand
Posts: 231
|
I'm taking a 101 course in Java, and i'm making a particular program... but I'm stuck at a certain point.
If the user input something like: 3 3 4 + - with spaces between the values. What I need to do is be able to separate the values into individual strings. So I'd have one string with "3", one with "3", one with "4", one with "+" and one with "-" It has me stumped... Any ideas? Thanks ![]() Yoonsi
__________________
Black computer case filled with Jam.
|
|
|
|
|
|
#2 (permalink) |
|
Gold Member
![]() Join Date: Jan 2008
Location: NC (Home of the HEELS!!)
Age: 25
Posts: 299
|
I studied some Java a little back, got any snippet of the code you are using right now?
__________________
System: Asus P5VD2-VM SE mATX Board 2 GB of Crucial DDR2-PC5300 Ram Intel Pentium D 3.2Ghz w/Thermaltake Fan/heatsink Nvidia GeForce 8600GT 512MB Video card Hitachi 500 GB SATA 2 Drive Power Up Black ATX Mid-Tower Case 550 W/ Power supply DVD Burner Windows XP Home SP2 |
|
|
|
|
|
#4 (permalink) |
|
Gold Member
![]() Join Date: Jan 2008
Location: NC (Home of the HEELS!!)
Age: 25
Posts: 299
|
Good luck!! = )
__________________
System: Asus P5VD2-VM SE mATX Board 2 GB of Crucial DDR2-PC5300 Ram Intel Pentium D 3.2Ghz w/Thermaltake Fan/heatsink Nvidia GeForce 8600GT 512MB Video card Hitachi 500 GB SATA 2 Drive Power Up Black ATX Mid-Tower Case 550 W/ Power supply DVD Burner Windows XP Home SP2 |
|
|
|
|
|
#6 (permalink) |
|
Silver Member
![]() Join Date: Aug 2006
Location: New Zealand
Posts: 231
|
Why wont this work...
It compliles fine, but when I run the program, I get an error StringIndexOutOfBoundsException: String index out of range exception -1 ![]() ![]() Code:
private int getMaxNumberOfTokens(String input) {
String [] expressionArray;
int numberOfTokens = 0;
expressionArray = new String [input.length()];
String expression = input;
int i = 1;
while ( i >= 1) {
if (expression.length() > 1){
expressionArray[i] = getToken(expression);
numberOfTokens++;
expression = removeBottomToken(expression);
i++;
} else {
expressionArray[i] = getToken(expression);
numberOfTokens++;
i = 0;
}
}
return numberOfTokens;
}
__________________
Black computer case filled with Jam.
|
|
|
|
|
|
#7 (permalink) |
|
Diamond Member
![]() Join Date: Sep 2006
Location: 127.0.0.1
Posts: 2,301
|
I'm somewhat proficient.
What line are you getting the error on? I'm not quite sure I follow what your doing there. Could you post your getToken() and removeBottomToken() code please?
__________________
I play Rugby, and no its not like it's sissy cousin with the pads. Last edited by Emperor_nero; 05-10-2008 at 04:36 PM. |
|
|
|
|
|
#8 (permalink) |
|
Gold Member
![]() Join Date: Jan 2008
Location: NC (Home of the HEELS!!)
Age: 25
Posts: 299
|
So, you want the program to add up, or what?
__________________
System: Asus P5VD2-VM SE mATX Board 2 GB of Crucial DDR2-PC5300 Ram Intel Pentium D 3.2Ghz w/Thermaltake Fan/heatsink Nvidia GeForce 8600GT 512MB Video card Hitachi 500 GB SATA 2 Drive Power Up Black ATX Mid-Tower Case 550 W/ Power supply DVD Burner Windows XP Home SP2 |
|
|
|
|
|
#9 (permalink) |
|
Silver Member
![]() Join Date: Aug 2006
Location: New Zealand
Posts: 231
|
Ah, so sorry everyone! I was so vague in what I asked....
well last night I was fully stressed, and was a bit tired... Lesson learned: Don't program at 2am!! Anyway, I managed to get it all right this morning. Guess a good sleep just cleared up things in my mind... Thanks everyone for your interest and I really appreciate it! If you want to see what I ended up with anyway, just let me know ^^ Yoonsi ![]()
__________________
Black computer case filled with Jam.
|
|
|
|
|
|
#10 (permalink) | |
|
Diamond Member
![]() Join Date: Sep 2006
Location: 127.0.0.1
Posts: 2,301
|
Quote:
![]() Yeah it sounds interesting, I'd like to see it. ![]()
__________________
I play Rugby, and no its not like it's sissy cousin with the pads. |
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Java Programming - Need URGENT help with CITY JUMPER - Java Programming | shariq | Computer Games and Consoles | 0 | 01-19-2007 08:04 AM |
| What does basic Java Programming language actually look like? | leeroyMarv | General Software | 3 | 06-09-2006 03:48 AM |
| Java problem.. | Hobo_man | Operating Systems | 2 | 03-03-2006 09:19 PM |
| Java Problems | Hobo_man | Operating Systems | 1 | 03-03-2006 07:46 PM |
| Java Runtime error box on XP? | leo | Operating Systems | 7 | 06-18-2005 12:31 AM |