I am trying to split a string into two different arrays based on multiple values
For example user inputs in the console window
2+4/8*9
I want only the numbers to be in an array
Arr[0] = 2;
Arr[1] = 4;
Arr[2] = 8;
Arr[3] = 9;
And then
Operator[0] = +;
Operator[1] = /;
Operator[2] = *;
I am familiar with split method that uses only one delimiter but how will I be able to split the string based on various number of delimiters?
Following is the latest code I have tried by looking at various articles on the internet but getting error
Scanner in = new Scanner(System.in);
System.out.println("Enter input");
s = in.toString();
String [] operators = s.split("+|-|*|/"); //Also tried s.split("\\+\\-\\*\\/")
for(int i = 0; i<operators.length; i++) {
System.out.println(operators[i]);
}