Converting inserted string to a compilable expression

后端 未结 5 1812
醉梦人生
醉梦人生 2021-01-23 07:45

I\'m somehow new to Java so my question can seem trivial, however i cannot find an answer to it anywhere in my books.

I want to initiatie a dialog with a user in which h

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-23 07:59

    How to convert a String into Arithmetic Expression

    import bsh.*;
    
     class Operation
     {
    
        public static void main(String[] args)throws Exception
        {
            Interpreter i=new Interpreter();
            int r=(Integer)i.eval(args[0]);
            System.out.println(r);
        }
    }
    

    for this we need a separate jar file named: bsh.jar file

    need to set classpath for above jar file

    source: http://ohmjavaclasses.blogspot.com/2011/11/how-to-convert-string-into-arithmetic.html

提交回复
热议问题