0

IS there any way to store this String value (or any other arithmatic equation) into an int variable ?

The equation is: String eq1= "10*2+5/4";

can eql be casted in int i;

i have tried explicit casting but it doesnt work.

Note that the equation String eq1= "10*2+5/4"; is just for example , the user can enter any other numerical equation with arithmetic operators + , - , / , * and %

I have to obtain the equation from JTextArea.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Check out: https://stackoverflow.com/questions/7441625/how-to-find-a-button-source-in-awt-calculator-homework/7441804#7441804 – camickr Jun 23 '21 at 13:48
  • You could use the integrated scripting engine to evaluate the formula and then use Integer.valueOf() to get the int value. – Ryan Jun 23 '21 at 13:52
  • What happens if the expression is not valid arithmetic? Say, "/4*+5x". Why do you need an int to represent the expression? Define the characteristics of the int (range, meaning, etc.). – Alan Jun 23 '21 at 13:53

0 Answers0