I need to implement the following:
Entry (a string):
5+45+100-125+5-10
Exit:
= 20
Here the code implemented only for positive numbers:
String operacion="10+200+3000";
int tam = operacion.length();
String A[] = new String[100];
int pos = 0;
int sum = 0;
String aux = "";
for(int i = 0; i<tam ; i++)
{
if(operacion.charAt(i) == '+')
{
A[pos] = aux;
pos++;
aux = "";
}
else
{
aux = aux + operacion.charAt(i);
}
}
A[pos] = aux;
pos++;
for(int i = 0; i<pos ; i++)
{
sum=sum+Integer.parseInt(A[i]);
}
System.out.println("= "+sum);
Exit
= 3210
The problem is that I can not do it for the negatives to do the operation.