Any help would be appreciated.
I am not trying to list the operators, ( I know that it would work that way) i want to know if i can put them in a bundle as i attempted in my code below (it did not work, anyone knows why? how to fix it?): }
double num1 = Double.parseDouble(token[0]);
double num2 = Double.parseDouble(token[2]);
double answer;
String function = "[+\\-*/]+"; //this
String[] token = input.split(function);//and this
String operator = token[1];//this is the operator
if (operator.equals(function)){
for (int i = 0; i<length; i++) {
}
System.out.println("Operation is " + token[1] + ", numbers are " + token[0] + " and " + token[2]);
}
else {
System.out.println("Your entry of "+ input + " is invalid");
}
}
first you should split .you can't access
token[0]
beforedeclare
tokensthen use array[index]
edit....
you should use .
matches
instead .equals
because .equals looking for entire String not regular expressioncomplete code
output>>
Access token after splitting input
And
wont work because delimiter wont be there in the String array after splitting.
the code may be like this