I have to perform a pow function while getting equation from string like "2 power 3"
. I know there is function Math.pow(a, b)
and also I can use for loop
to achieve this , but the problem is both methods needs integer and I have equation in string. I don't know how to parse this string and separate both variables. And there is another problem. my equation could get little bit complex as well. for instance it could be like "2+3*5/5 power 2"
public class CalculationActivity extends AppCompatActivity {
EditText editText;
Button btnCalc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calculation);
editText=findViewById(R.id.et_regular_dep);
btnCalc=findViewById(R.id.btnCalculate);
btnCalc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String equation= editText.getText().toString();
CalculateResult(equation);
}
});
}
private void CalculateResult(String equation) {
// here to perform power function
}
}