How to calculate a value from a user input? (Java) -
I am trying to write a program that will take an input from the user and calculate the total input. For example, if the user input "5 + 30 * 2" would be output "65" I have still spent hours on it and are unable to get the correct solution. Does anybody know how I do this?
With JDK1.6, you have built-in reply engine.
This is testing and working.
import java.io. *; Import javax.script.ScriptEngineManager; Import javax.script.ScriptEngine; Import java.util.Scanner; Import javax.script.ScriptException; Public class MathExpress {public static zero main (string [] args throws scriptException {scanner console = new scanner (System.in); System.out.println ("Enter your Artificial Operation"); String math = console.nextLine (); ScriptEngineManager mgr = New ScriptEngineManager (); Script engine engine = mgr.jetenginebinem ("javascript"); Println (engine.eval (Mathex)); }}
Comments
Post a Comment