I wanted this to work so badly and then I was met with devastation when I got an error. Essentially i have an expression, and I want to replace the values of string with my integer variable dx so that if i were to parse it to an int the value would be the coefficients multiplied by the dx
int dx = 9;
String function = "7x + 9x + 7x";
String sumRepeated = function.replaceAll("x", "*(dx)");
System.out.println(sumRepeated);
int sum1 = Integer.parseInt(sumRepeated);
I thought because the String output was 7*(dx) + 9*(dx) + 7*(dx) that if I were to simply parse the string to an int it would return the value of the number which happens to be 207 because dx is a variable but alas my fears caught up to me and my world caved in, the joyous flame of passion had been extinguished as i saw the red java exception.