I have a linear expression which I have to use for some calculation purpose. But I can not manage to use it properly by separating on the basis of operators. i.e I have an expression
"c*(a+b)+(a-b)"
from which I have to extract c,(a+b),(a-b) .I am able to separate c from there but I can not separate (a+b) and (a-b) .I am doing this
String linearExp="c*(a+b)+(a-b)";
String leftOperators=null;
String rightOperators=null;
for(int i=0;i<linearExp.length();i++){
leftOperators=linearExp.substring(0,linearExp.lastIndexOf("*"));
rightOperators=linearExp.substring(linearExp.lastIndexOf("*")+1);
}
System.out.println(leftOperators);
System.out.println(rightOperators);
This is doing output like c & (a+b)+(a-b).But I a need (a+b) &(a-b) separate also.somebody please help