• Post Reply Bookmark Topic Watch Topic
  • New Topic

send the formula from another place  RSS feed

 
Muhammad Shamsher Khan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody!

I hope that all you will be fine. My Question is with reference of java.

I want to make formula syntax in another place and it will go in backend process and execute. for example:

public static void main(String args[])
{
try
{
int myResult = myFormula("(a * b)/c");
System.out.println(myResult);

}

}

public int myFormul(String Str_Variable)
{
int a = 32, b = 20, c = 2,result = 0;
try
{

result = Str_Variable;
return result;

}
}


How is it possible in java? please write any example for it.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Muhammad,
you should be aware that cross-posting between forums is not considered good manner. Please be careful the next time
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you need is an expression evaluator, which evaluates an expression given as a string with respect to variables you have in your code. One evaluator I like is JEP, which has the benefit of being free.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!