Please help me with my code. i'm using an arraylist named tempAns, it contain values [2, 9, 2]. i've tried adding the last two numbers then replace them with the right answer so the result will be [2, 11]. but somehow, the output was always [9, 11]. it seems like it's deleting duplicate values.
else if(scan.equals("+"))
{
double num2 = Double.parseDouble(tempAns.get(tempAns.size()-1));
double num1 = Double.parseDouble(tempAns.get(tempAns.size()-2));
double ans = num1 + num2;
String stringAns = Double.toString(ans);
System.out.println("before deleting: " +tempAns + "\n");
tempAns.remove(tempAns.get(tempAns.size()-1));
tempAns.remove(tempAns.get(tempAns.size()-1));
System.out.println("before adding: " +tempAns);
tempAns.add(stringAns);
System.out.println(num1 + " + " +num2+ " = " +ans);
System.out.println("after deleting: " +tempAns + "\n");
}