Im trying to create a calculator similar to the windows standard calculator where in when you click "5" and then clicked "+" by mistake you just have to click "-" for the output to be "5 -" not "5 +". Problem is i don't know howto do that with my current code.

try { if(inpuDisplay.contains(".")) { doubleResult = new Double(Double.parseDouble(inpuDisplay)).toString(); inpuDisplay = doubleResult; } else { doubleResult = new Integer(Integer.parseInt(inpuDisplay)).toString(); inpuDisplay = doubleResult; } resDisplay = inpuDisplay + " + "; res2Display = res2Display + resDisplay; inpu2Display = display.getText().toString(); input.setText(res2Display); display.setText(""); if(add == true) { result = result + Double.parseDouble(inpu2Display); minus = false; mul = false; div = false; } if(minus == true) { if(result == 0) { result = Double.parseDouble(inpu2Display); } else if(result < 0) { result = result - Double.parseDouble(inpu2Display); } else if(result > 0) { result = result - Double.parseDouble(inpu2Display); } minus = false; add = true; } if(mul == true) { if(result == 0) { result = Double.parseDouble(inpu2Display); } else { result = result * Double.parseDouble(inpu2Display); } mul = false; add = true; } if(div == true) { if(result == 0) { result = Double.parseDouble(inpu2Display); } else { result = result / Double.parseDouble(inpu2Display); } div = false; add = true; } if(result % 1 == 0) { display.setText(Integer.toString((int)result)); } else { display.setText(Double.toString(result)); } inpuDisplay = ""; inpu2Display = ""; } catch(Exception e) { }

NOTE: The above code is executed when yhe "+" button is clicked. And is working i just have to add the replace sign function. Could someone please help?