Anyone here proficient in Java?

Yoonsi

New Member
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 :D
Yoonsi
 
Thanks for the reply! Funnily enough, I think I have something that might work! If it doesn't though Ill post what I have.
 
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
:confused::confused:
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;
	}
 
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?
 
Last edited:
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 :P
 
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 :P

Haha, wow that sounds so familiar, I've found that at about 12am my programming brain shuts and I can't do anymore. :P

Yeah it sounds interesting, I'd like to see it. :)
 
Back
Top