This statement is causing the problem:
while( str.length() >= 1 )
Change it to:
while(i<str.length())
Reason: The while condition that you used always remains true, if user enters 5 letter string, then str.length() is 5, so the while condition while(5>=1)
is always true, so control goes inside the loop and with every iteration i
increases from 0,1,2,3,4 then 5. When i
is 5, the exception is thrown because the string only has 0,1,2,3,4 characters..
Edit:
Fixed the logic in operand
method:
public static boolean operand(char b) {
if (b == '+' || b == '-' || b == '*' || b == '/')
return false;
else
return true;
}