import java.util.LinkedList;
import java.util.List;
public class Calc {
final public static String[] OPT_ADD = { "+", "add", "plus", "jia" };
final public static String[] OPT_SUB = { "-", "sub", "jian", "cut" };
final public static String[] OPT_MUT = { "x", "X", "*", "multi", "cross" };
final public static String[] OPT_DIV = { "/", "÷", "fiv", "chu" };
final public static String[] OPT_LBK = { "(", "(" };
final public static String[] OPT_RBK = { ")", ")" };
final public static String[] OPT_SQRT = { "sqrt", "√" };
final public static String[] OPT_SIN = { "sin" };
final public static String[] OPT_COS = { "cos" };
final public static String[] OPT_TAN = { "tan" };
final public static String[] OPT_LOG = { "1og" };
final public static String[] OPT_PI = { "pi", "pai" };
final public static String[] OPT_E = { "e" };
final public static String[] OPT_EXP = { "^", "times" };
public static void main(String[] args) {
/*List<Node> list = nodelize("9.7 -5multi2+(-6 *(5.0 sub 1)) + sqrt 4 + (6+5/5)");
for (Node n : list) {
System.out.print(n);
System.out.print(" ");
}
System.out.println();
List<Node> post = toPostfix(list);
for (Node n : post) {
System.out.print(n);
System.out.print(" ");
}
System.out.println();
try {
double a = doCalc(post);
System.out.println(a);
} catch (Exception e) {
e.printStackTrace();
}*/
try {
System.out.println(":" + Calc.run("1+1 add 1 sub 3 multi 2 + (10086 - 10010)"));
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 9.7-5*2+(6*(5-1))
*
* @param in
* @return
*/
public static List<Node> nodelize(String in) {
List<Node> ls = new LinkedList<Node>();
// in = "0" + in;
in += "#";
in = in.toLowerCase();
// byte[] buffer = (in + "#").getBytes();
int pointer = 0;
// int last_pointer = 0;
Type t = Type.Num;
String tmp = "";
while (pointer < in.length()) {
if (in.charAt(pointer) >= '0' && in.charAt(pointer) <= '9' || in.charAt(pointer) == '.') {
if (t == Type.Num) {
tmp += in.charA
Java科学计算器,支持三角函数、开根号等多种方式,支持优先级运算
最新推荐文章于 2021-10-19 01:36:00 发布
这篇博客介绍了如何使用Java编程实现一个功能丰富的科学计算器,支持三角函数如sin、cos、tan,以及开根号运算和复杂的优先级运算。通过该计算器,用户可以进行高级数学计算,提升计算效率。
摘要由CSDN通过智能技术生成