I want convert a string to an integer but it doesn't work. I think the problem is that the string isn't "clean", see this example:
public class Test{
public static void main(String[] args){
String str = "(2+2)";
int conv = Integer.parseInt(str);
System.out.println(conv);
}
}
Why doesn't it work? I could also define int x = (2+2);
without any problems.
What exactly is the problem here and is there an easy way to solve it?
*Purpose: I have just finished a code that will detect if a math expression is correct (brackets, signs, .. arithmetic stuff). As example the string input is ((8+7)*2)
and the program will return true.
But now I need to find a way to calculate this and return the solution of it, 30
. (If you want I can post my code too but I didn't want make this question seemingly long.)