I have placed below my problem is as simplified as possible. Given a string containing a literal mathematical expression I want to get the same expression by converting letters to numbers taking values from a map. I posted below my code for any help from you guys.
public class Prova {
public static void main(String[] argv) {
//mathematical expression
String expr = "(a*b)+(b/a)"; //(15*60)+(60/15)
//Map of numeric values
HashMap<String, Double> itemval = new HashMap();
itemval.put("a", 15.0);
itemval.put("b", 60.0);
System.out.println("itemval: " + itemval);
System.out.println("expr: " + expr);
//convert literal expression numerically
char[] nc = expr.toCharArray();
for (int t = 0; t < nc.length; t++) {
char pippo = nc[t];
for (String key : itemval.keySet()) {
if (key.equals(pippo)) {
System.out.println("pippo: " + itemval.get(key));
}
}
System.out.print(nc[t]);
}
}
}
what I want is to get an output like (15 * 60) + (60/15) Thanks in advance...