Added the Java version

Well I'm sorry I couldn't upgrade your C++ program. My knowledge in C++ is painfully limited.
On the other hand , I've made a similar type in Java which borrows your algorithm. It also uses a handy library method which parses the expression for x during runtime.
But essentially , it works quite the same.

![](http://i45.tinypic.com/11bulpv.png)