basically, i need to input an equation with an 'x' value (ex. 3x + 5). then the next input would be the value of x. all the x in the equation will then be replaced by the given value. what i did was to input the equation as string and then used string.replace to replace x with the given value.
System.out.print("enter equation: ");
Scanner sc = new Scanner(System.in);
String equation = sc.nextLine();
System.out.print("value of x: ");
int x=sc.nextInt();
String xx= Integer.toString(x);
equation= equation.replace("x",xx);
System.out.println(equation);
problem is, since the string equation may have "+" or "-", i can't convert the string to int. any suggestions what to convert the string into such that it can be solvable? also if the x is next to a number (ex. 4x) is there a way that it can be multiplied?