I have a little doubt about a graphing calculator that I'm doing in java. What happens is that I have everything done, but there is a problem pressing the same button and operate all the numbers. Then I leave the code:
private void igualActionPerformed(java.awt.event.ActionEvent evt) {
Double num = Double.parseDouble(pantalla.getText().substring(aux,pantalla.getText().length()));
numeros.add(num);
int iterador = -1;
for (int i = 0; i <= operadores.size() - 1; i++) {
switch(operadores.get(i)){
case '+':
resultado = resultado + (numeros.get(0) + numeros.get(1));
case '-':
resultado = resultado - numeros.get(iterador+1);
case '*':
resultado = resultado * numeros.get(iterador+1);
case '/':
resultado = resultado / numeros.get(iterador+1);
iterador++;
}
System.out.println(resultado);
System.out.println(numeros.get(0) + numeros.get(1));
}
}
As you can see, inside the for all the operations process is done, the point is that if you set, inside the case for addition, I keep the result of adding the index 0 and 1 of the ArrayList numbers in a variable called " result ".
The problem is that I print it, and then I print the direct sum and I get two totally different results, then I leave what the console prints:
run:
10.0
20.0