I have a trouble with my code . I think the problem is about delims=[+,-,*,/]+
. when i write if (delims.equals("[+]+"))
for ex, it takes only [+]. however delims is not equal just [+]. Ithink you got what i mean. delims is equal [+,-,*,/]+.
public static void main(String[] args) {
System.out.println("Please enter your calculation");
Scanner sc = new Scanner(System.in);
String s=sc.next();
String delims="[+,-,*,/]+";
String[] tokens=s.split(delims);
for(int i=0; i<1; i++){
String s1=tokens[i];
for (int j=1; j<2; j++){
String s2=tokens[j];
double n1=Double.parseDouble(s1);
double n2=Double.parseDouble(s2);
if (delims.equals("[+]+")){
System.out.println(n1+n2);
System.exit(0); }
if (delims.equals("[-]+")){
System.out.println(n1-n2);
System.exit(0);}
if (delims.equals("[*]+")){
System.out.println(n1*n2);
System.exit(0);}
if (delims.equals("[/]+")){
System.out.println(n1/n2);
System.exit(0);
}
}}}}