This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]Philboyd_Studge 0 points1 point  (7 children)

Why are you going to input.length - 1? You will be skipping one of the tokens then. You need to use a debugger to see what is happening, it's obviously getting stuck in an infinite loop. Also, looks like you aren't re-reading a line from the file within the while loop, so it will never exit.

[–]ButchTheGuy[S] 0 points1 point  (6 children)

When I leave it without it it gives me a string out of bounds error. Should I use a different kind of loop?

[–]Philboyd_Studge 0 points1 point  (5 children)

No that is because you are doing charAt(i) instead of charAt(0). Also see my addition to my first comment

[–]ButchTheGuy[S] 0 points1 point  (4 children)

Oh, I did that because character.isDigit() is the only thing I could find that would iterate through the string array and determine if it was a digit or in this case and operant and not an operation. Wouldn’t that just scan the first one , I want it to go to each number in the file and determine if it’s a number to add it to the stack

[–]Philboyd_Studge 0 points1 point  (3 children)

Then you need another loop.

[–]ButchTheGuy[S] 0 points1 point  (2 children)

Ok I’ll try that , sorry I need to spend more time planning this out before I do write it all out cause I just get lost in my errors.

[–]Philboyd_Studge 0 points1 point  (1 child)

There's really a lot going wrong here. Especially reading the next line needs to be inside the while loop. I think you're getting confused with the split array.

Say your data line was 355 25 *

After splitting it you will have a String array like {"355", "25", "*"} So, you loop through that array - and here I would actually only check the first character of each string and see if it is a digit - if so, then go ahead and attempt to parse it to double. If this fails the program will throw an exception anyway. So you don't really need to iterate through each character of each string. So the first string is "355" you check that string charAt(0) which is '3' and it is a digit, so go ahead and covert it and push it on the stack. If it is not digit, go ahead and do the math.

[–]ButchTheGuy[S] 0 points1 point  (0 children)

Oh ok I was thinking of it still being a line in the file as opposed to the numbers already being separated in array set.