JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.util.Scanner;
public class Mathematics1 {
public static void calculate (double correctAnswer, String equations) throws ScriptException {
String[] splitEquations = equations.replaceAll("[()]", "").split(" ");
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
boolean found = false;
double correct = (double) correctAnswer;
int i = 0;
while (i < splitEquations.length) {
String equation = splitEquations[i];
// int answer = (int) engine.eval(equation);
double answer = Double.parseDouble (engine.eval (equation).toString());
System.out.println (answer);
if (answer == correct) {
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run