0

I want to make a calculator App. For this I need to be able to split a string into two when there is an operand between them. I tried my code like this:

String[] operation= display.split(Pattern.quote(currentOperator)); currentOperator contain my operator i.e + - / or *

I tried entering 12 + 12

When I displayed my operation[0] and operation1 result shown is 1 and +1 enter image description here

CaptainBli
  • 4,121
  • 4
  • 39
  • 58

1 Answers1

0

Why not use a format such as operator:value:value eg. +:12:12 In this case you could use:

String[]example=yourString.split(":");
if(example.length==3){
String operator=example[0];
int value1=Integer.parseInt(example[1]);
int value2=Integer.parseInt(example[2]);
}