I\'m looking for a way to shorten this code up and avoid repeating code and if statements. What I\'m doing is creating a calculator that searches strings for operators &quo
For changing the code you could use a switch statement and putting some of the redundant code before or after the switch.
int left = Integer.parseInt(exp.substring(0,i));
int right = Integer.parseInt(exp.substring(i+1,exp.length()));
switch(exp.charAt(i)){
case '*':
primeResult = left * right;
break;
case '/':
...
break;
case '+':
...
break;
case '-':
...
break;
default:
... // Error Handling.
}
System.out.println(primeResult);