我有一系列字符串,通过BufferReader读入,如下所示。
在每个点上,数学表达式被添加到数组列表中,我想,能够在Android中评估这些表达式,但目前我不知道如何
即。我希望能够说出作为calcilation expressionList.get(0)= 1.92等的结果。
我想完成此操作,不使用其他代码库。
读入表达式的示例:
"(((10 + 9.2)/50) *5)"
"((3 - 1.2)*20)"
"51 * 100"
"2 / 132"
etc.
我的代码:
ArrayList<String> expressionList = new ArrayList<>();
FileInputStream is = new FileInputStream(fileLocation);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line = reader.readLine();
while (line != null) {
line = reader.readLine();
if (line.contains("/") || line.contains("*") || line.contains("+") || line.contains("-")){
expressionList.add(line);
}
}