How to convert String with '*' into integer

recently I have been working on creating a calculator that will convert a string into an integer. I know that this can be done through .parseInt() and .valueOf() methods but these both don't work when the string has an asterisk in it (*) and I was wondering if there was a simple method of converting a string with an asterisk in it to an integer without repetition.

An example would be this String.

String formula = "123 * 4";

When converting this into an integer, the .parseInt() and .valueOf() methods return the "NumberFormatException" error.

Is there any way of converting a string into an integer when the string has an asterisk in it?

What I am hoping would happen is 123 is multiplied by 4. So the answer would be 492.

1 answer