Advertisement

Udemy WW Udemy WW

Tuesday 29 November 2011

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);
    }
}
you just need to compile above code and interpret as follows
C:\java Operaraion 1+2+\4*6

9 comments:

  1. Wov!!! Nice one yr... good keep it's up! dear bro. Nice Blogs...

    ReplyDelete
  2. what is bsh.*; does it comes with standard sdk or need to include separately.

    ReplyDelete
  3. @ratnesh for this external jar file is need to attach
    you can google for this

    ReplyDelete
  4. what is bsh.*; I am not understand so explain the bsh.*;

    ReplyDelete
    Replies
    1. you need to download external jar file (bash) and set path for it

      Delete
    2. You can download bsh jar file from following link
      http://www.java2s.com/Code/Jar/b/Downloadbshjar.htm

      Delete

Advertisement

Udemy WW