It is not just string split, you need other checks too, like:
1) Split the string based on =
pattern
if(stringValue.matches("="))
{
String[] valArray = stringValue.split("=");
}
else
{
// do something else
}
This will give you an array of string. Now loop through string array and check for below conditions.
2) Check if there is numeric
value present
ie: valArray[].matches("\d");
3) If numeric
value is present, check if there is more than 1 occurrences of alphabet numeric
values present (to see if there are more than 1 variables present)
This is to check if alphabet is present in any of split strings >> valArray[].matches("\D");
4) Finally, if there is only 1 numeric value and 1 alphanumeric value present, store key and value.
5) If there are more than 1 occurrences of empty variables, then you will need to skip the operation(plus, minus ...) until you have variable value present in key-value array.
You can check this by checking your key-value pair array. You don't store key-value if the value if empty.
6) If =
is not present then check for print
in the string and do the print operation.
ie:
if(stringValue.matches("print"));
{
//Do something
}
Note: stringValue
is your console input line.