Well. I cannot give you code… I can give you some advice..
- Split the String based on semicolon (;).
- For each String in the array (which you got after splitting, except the last one) split it again based on “=”.
- Take the RHS of the split String and parse it as integer.
- Now parse the last String which you got after splitting the main String based on “;”. See what operation is present inside it using contains(). Also check what are the variables involved using contains(). Check the variables int value (which you got after splitting based on “=” and using Integer.parseInt on the RHS part.)
- Perform the operation based on what the String contains (*,+,-,/) . You could use a switch statement for this.
1
solved Java – How to write a code that Solve equation inside a String? [closed]