I'm trying to figure to figure out where I can be more efficient in my code, rather than having repeating IF statements. It's currently taking my NB IDE 25 seconds to run my basic Calculator app.
I'd appreciate any help, as I can only find code snippets but not an actual method of where I should first look to cut down.
My current code for my equals function is:
private void jBtn18ActionPerformed(java.awt.event.ActionEvent evt) {
String finalAnswer;
secondnumber = Double.parseDouble(jtxtDisplay.getText());
if (operations == "+")
{
result = firstnumber + secondnumber;
String answer = String.format("%.0f",result);
jtxtDisplay.setText(answer);
}
else if (operations == "-")
{
result = firstnumber - secondnumber;
String answer = String.format("%.0f",result);
jtxtDisplay.setText(answer);
}
else if (operations == "/")
{
result = firstnumber / secondnumber;
String answer = String.format("%.0f",result);
jtxtDisplay.setText(answer);
}
else if (operations == "*")
{
result = firstnumber * secondnumber;
String answer = String.format("%.0f",result);
jtxtDisplay.setText(answer);
}
else if (operations == "%")
{
result = firstnumber % secondnumber;
String answer = String.format("%.0f",result);
jtxtDisplay.setText(answer);
}
}