Computer Science, asked by aditi171945, 5 months ago

convert into java expression: | ab/c |​

Answers

Answered by MrPrince07
0

Explanation:

2

I would recommend using a "helper" method that returns a boolean result, so the statement would look something like this

String abc = "a>10";

if(stringToConditional("a>b"))

{

//TO SOME TASK

}

private boolean stringToConditional(String str)

{

//code here

}

From there, the "helper" method can split the string into three parts using regex. A helpful, abet dense, tutorial can be found here. From there, a and b can be parsed using JSE methods. It looks something like this:

String a = "1.21";

double a1 = Double.parseDouble(a); //a1 is now equal to 1.21

From there, the next step would be to compare the conditional string (">", "<=", "==", etc.) to a list of known operators, and then testing the operation and returning the result as the method's boolean return. For example:

String operator = ">=";

if (operator.equals(">="))

{

return a1>=b1;

}

...

Hopefully I wasn't too unclear or off the mark. I'd be happy to elaborate, clarify or simplify. Good Luck!

Answered by Oreki
2

\textsf{\large Given Expression}

    |ab\: / \: c|

\textsf{\large Java Expression}

    \texttt{Math.abs(a * b / c);}

Similar questions