I would like to thank the previous person who helped me with this.
I am writing a
java application to parse a command line
string such as java ParseEval 3.5 - 7.0 + 8.1. Only + and - operations are allowed. The string can contain spaces. I am at the point where I can find the position of the + or minus signs, but I am having trouble putting the numbers to be evaluated into a statement that can be evaluated.
I tried the method Gautam gave me and it worked. Thank you, because I learned something new. However, I am taking a java class and we haven't gone over push yet. Therefore I need to do this problem using charAt and then putting the numbers between the signs in a substring. I keep getting stuck here, when trying to specify each of the positions in the substring to get the calculation. We also need to allow for the case where the 1st argument is a sign. I'll show you what I have so far. Thank you for your help.
class ParseEval{
public static void main (String args[]) {
if (args.length==0) return;
String s = new String ();
char ch=0;
for (int i = 0; i < args.length; i++)
s=s.concat(args[i]);
for(int j=0; j < s.length();j++){
ch = s.charAt(j);
if ( ch=='+' || ch=='-'){
System.out.println("Ch is " +ch);
System.out.println("position is " +j);
}
}
}
}
Thanks again.