阿里巴巴做网站的电话号码,平面设计培训学校一年学费,做物流网站模块,wordpress 3d线条目录 文章目录 目录介绍开始实战引入数学表达式计算库引入流程图代码生成库开始进行生成 介绍
大家好 今天我们来分享一个新知识#xff0c;将数学表达式的整个计算过程#xff0c;以及计算繁多结果在 Java 中绘制出来#xff0c;计算机中的数学表达式计算的功能很常见了将数学表达式的整个计算过程以及计算繁多结果在 Java 中绘制出来计算机中的数学表达式计算的功能很常见了但是今天我们要使用一个工具它可以将 整个计算过程 使用 Java 绘制成为 mermaid 的流程图
开始实战 引入数学表达式计算库
mathematical-expression 库是一个专注于进行数学解析的库 它具有 Java Python C 三种 API在最近发布的 Java 版本中提供了数学表达式的解析功能接下来我们就来引入一下吧
dependencygroupIdio.github.BeardedManZhao/groupIdartifactIdmathematical-expression/artifactIdversion1.3.5/version
/dependency引入流程图代码生成库
您只需要导入下面的依赖坐标就可以自动实现相关组件的导入。这个库将会帮助您将计算组件的计算过程绘制成一个流程图。
dependencygroupIdio.github.BeardedManZhao/groupIdartifactIdvarFormatter/artifactIdversion1.0.4/version
/dependency开始进行生成
导入了库之后我们就可以像下面一样进行生成流程图。
import core.Mathematical_Expression;
import core.calculation.Calculation;
import core.container.LogResults;
import exceptional.WrongFormat;
import top.lingyuzhao.varFormatter.core.VarFormatter;public class MAIN {public static void main(String[] args) throws WrongFormat {// 获取到一个有括号计算组件 您可以根据需求更换组件final Calculation instance Mathematical_Expression.getInstance(Mathematical_Expression.bracketsCalculation2);// 然后进行一个简单的检查 这里我们要查询 1 2 ^ 4 - 2 * 3 2 的执行过程final String s 1 2 ^ (2 (10 - 7)) * 3 2;instance.check(s);// 我们可以通过 explain 获取到执行过程 它会返回一个对象 这个对象中有一个 result 字段 这个字段就是计算出来的结果final LogResults explain instance.explain(s, true);System.out.println(计算结果 explain.getResult());// 事实上 LogResults 更大的作用是进行执行过程可视化 下面就是一个例子// 设置输出图的时候不拼接名字因为在这里有很多的变量 需要进行关联的拼接名字就不好关联了explain.setNameJoin(false);// 通过我们引入的 VarFormatter 可以很方便地进行格式化 我们在这里格式化为 MERMAID 图 代码System.out.println(graph LR);System.out.println(VarFormatter.MERMAID.getFormatter(true).format(explain));}
}程序运行之后的结果如下所示
E:\RunTime\jdk8\jdk-8u351\bin\java.exe -javaagent:D:\Liming\MyApplication\IntelliJ_IDEA\IntelliJ IDEA 2021.3.2\lib\idea_rt.jar52509:D:\Liming\MyApplication\IntelliJ_IDEA\IntelliJ IDEA 2021.3.2\bin -Dfile.encodingUTF-8 -classpath E:\RunTime\jdk8\jdk-8u351\jre\lib\charsets.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\deploy.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\ext\access-bridge-64.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\ext\cldrdata.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\ext\dnsns.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\ext\jaccess.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\ext\jfxrt.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\ext\localedata.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\ext\nashorn.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\ext\sunec.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\ext\sunjce_provider.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\ext\sunmscapi.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\ext\sunpkcs11.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\ext\zipfs.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\javaws.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\jce.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\jfr.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\jfxswt.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\jsse.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\management-agent.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\plugin.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\resources.jar;E:\RunTime\jdk8\jdk-8u351\jre\lib\rt.jar;G:\MyGithub\mathematical-expression\target\test-classes;G:\MyGithub\mathematical-expression\target\classes;G:\RunTime\MAVEN\MAVEN_BASE\org\apache\logging\log4j\log4j-slf4j-impl\2.20.0\log4j-slf4j-impl-2.20.0.jar;G:\RunTime\MAVEN\MAVEN_BASE\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;G:\RunTime\MAVEN\MAVEN_BASE\org\apache\logging\log4j\log4j-api\2.20.0\log4j-api-2.20.0.jar;G:\RunTime\MAVEN\MAVEN_BASE\org\apache\logging\log4j\log4j-core\2.20.0\log4j-core-2.20.0.jar;G:\RunTime\MAVEN\MAVEN_BASE\io\github\BeardedManZhao\varFormatter\1.0.4\varFormatter-1.0.4.jar MAIN
[INFO][Calculation Management][24-05-13:06]] : Welcome to [mathematical expression]
[INFO][Calculation Management][24-05-13:06]] : Start time Mon May 13 18:20:27 CST 2024
[INFO][Calculation Management][24-05-13:06]] : version: 1.35
[INFO][Calculation Management][24-05-13:06]] : Calculation component manager initialized successfully
[INFO][Calculation Management][24-05-13:06]] : For more information, see: https://github.com/BeardedManZhao/mathematical-expression.git
[INFO][Calculation Management][24-05-13:06]] : --------------------------------------------------------------------------------------------------
[INFO][Calculation Management][24-05-13:06]] : A computing component is registered PrefixExpressionOperation
[INFO][Calculation Management][24-05-13:06]] : A computing component is registered bracketsCalculation2
计算结果99.0
graph LR
f_-1523352178(1 2 ^ (2 (10 - 7)) * 3 2)
f_-1523352178MapMapf_1563255009
f_1563255009(2 (10 - 7))
f_1563255009MapMapf_1448155011
f_1448155011(10 - 7)
f_1448155011MapMapf_1507337
f_1507337(10-70)
f_1507337MapMapf_1507337_优先f_1507337_优先MapMapf_1571371271_计算
f_1571371271(10.0 - 7.0)
f_1571371271_计算MapString/Numberf_1571371271
f_1571371271--Mapvalue--f_1571371271v{3.0}
f_1571371271_计算MapMapf_1507337_最终f_1507337_最终MapMapf_1481348562_计算
f_1481348562(3.0 0.0)
f_1481348562_计算MapString/Numberf_1481348562
f_1481348562--Mapvalue--f_1481348562v{3.0}
f_1481348562_计算MapString/Numberresult
result--Mapvalue--resultv{3.0}
f_1507337MapMapf_1507337_最终f_1507337_最终MapMapf_1481348562_计算
f_1481348562(3.0 0.0)
f_1481348562_计算MapString/Numberf_1481348562
f_1481348562--Mapvalue--f_1481348562v{3.0}
f_1481348562_计算MapString/Numberresult
result--Mapvalue--resultv{3.0}
f_1563255009MapMapf_47507548
f_47507548(23.00)
f_47507548MapMapf_47507548_优先f_47507548_优先MapMapf_-1006161388_计算
f_-1006161388(2.0 3.0)
f_-1006161388_计算MapString/Numberf_-1006161388
f_-1006161388--Mapvalue--f_-1006161388v{5.0}
f_-1006161388_计算MapMapf_47507548_最终f_47507548_最终MapMapf_-2133560364_计算
f_-2133560364(5.0 0.0)
f_-2133560364_计算MapString/Numberf_-2133560364
f_-2133560364--Mapvalue--f_-2133560364v{5.0}
f_-2133560364_计算MapString/Numberresult
result--Mapvalue--resultv{5.0}
f_47507548MapMapf_47507548_最终f_47507548_最终MapMapf_-2133560364_计算
f_-2133560364(5.0 0.0)
f_-2133560364_计算MapString/Numberf_-2133560364
f_-2133560364--Mapvalue--f_-2133560364v{5.0}
f_-2133560364_计算MapString/Numberresult
result--Mapvalue--resultv{5.0}
f_-1523352178MapMapf_-418786079
f_-418786079(12^5.0*320)
f_-418786079MapMapf_-418786079_优先f_-418786079_优先MapMapf_-959059895_计算
f_-959059895(2.0 ^ 5.0)
f_-959059895_计算MapString/Numberf_-959059895
f_-959059895--Mapvalue--f_-959059895v{32.0}
f_-959059895_计算MapMapf_1855628224_计算
f_1855628224(32.0 * 3.0)
f_1855628224_计算MapString/Numberf_1855628224
f_1855628224--Mapvalue--f_1855628224v{96.0}
f_1855628224_计算MapMapf_2037586494_计算
f_2037586494(96.0 2.0)
f_2037586494_计算MapString/Numberf_2037586494
f_2037586494--Mapvalue--f_2037586494v{98.0}
f_2037586494_计算MapMapf_-418786079_最终f_-418786079_最终MapMapf_-929530109_计算
f_-929530109(1.0 98.0)
f_-929530109_计算MapString/Numberf_-929530109
f_-929530109--Mapvalue--f_-929530109v{99.0}
f_-929530109_计算MapString/Numberresult
result--Mapvalue--resultv{99.0}
f_-418786079MapMapf_-418786079_最终f_-418786079_最终MapMapf_-929530109_计算
f_-929530109(1.0 98.0)
f_-929530109_计算MapString/Numberf_-929530109
f_-929530109--Mapvalue--f_-929530109v{99.0}
f_-929530109_计算MapString/Numberresult
result--Mapvalue--resultv{99.0}进程已结束退出代码为 0
程序运行之后的结果中有 mermaid 的图代码我们在下面将其展示了出来 供大家观看 #mermaid-svg-AumWcHBTEmQfunwR {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-AumWcHBTEmQfunwR .error-icon{fill:#552222;}#mermaid-svg-AumWcHBTEmQfunwR .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-AumWcHBTEmQfunwR .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-AumWcHBTEmQfunwR .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-AumWcHBTEmQfunwR .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-AumWcHBTEmQfunwR .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-AumWcHBTEmQfunwR .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-AumWcHBTEmQfunwR .marker{fill:#333333;stroke:#333333;}#mermaid-svg-AumWcHBTEmQfunwR .marker.cross{stroke:#333333;}#mermaid-svg-AumWcHBTEmQfunwR svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-AumWcHBTEmQfunwR .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-AumWcHBTEmQfunwR .cluster-label text{fill:#333;}#mermaid-svg-AumWcHBTEmQfunwR .cluster-label span{color:#333;}#mermaid-svg-AumWcHBTEmQfunwR .label text,#mermaid-svg-AumWcHBTEmQfunwR span{fill:#333;color:#333;}#mermaid-svg-AumWcHBTEmQfunwR .node rect,#mermaid-svg-AumWcHBTEmQfunwR .node circle,#mermaid-svg-AumWcHBTEmQfunwR .node ellipse,#mermaid-svg-AumWcHBTEmQfunwR .node polygon,#mermaid-svg-AumWcHBTEmQfunwR .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-AumWcHBTEmQfunwR .node .label{text-align:center;}#mermaid-svg-AumWcHBTEmQfunwR .node.clickable{cursor:pointer;}#mermaid-svg-AumWcHBTEmQfunwR .arrowheadPath{fill:#333333;}#mermaid-svg-AumWcHBTEmQfunwR .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-AumWcHBTEmQfunwR .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-AumWcHBTEmQfunwR .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-AumWcHBTEmQfunwR .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-AumWcHBTEmQfunwR .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-AumWcHBTEmQfunwR .cluster text{fill:#333;}#mermaid-svg-AumWcHBTEmQfunwR .cluster span{color:#333;}#mermaid-svg-AumWcHBTEmQfunwR div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-AumWcHBTEmQfunwR :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} MapMap MapMap MapMap MapMap MapMap MapString/Number Mapvalue MapMap MapMap MapString/Number Mapvalue MapString/Number Mapvalue MapMap MapMap MapString/Number Mapvalue MapString/Number Mapvalue MapMap MapMap MapMap MapString/Number Mapvalue MapMap MapMap MapString/Number Mapvalue MapString/Number Mapvalue MapMap MapMap MapString/Number Mapvalue MapString/Number Mapvalue MapMap MapMap MapMap MapString/Number Mapvalue MapMap MapString/Number Mapvalue MapMap MapString/Number Mapvalue MapMap MapMap MapString/Number Mapvalue MapString/Number Mapvalue MapMap MapMap MapString/Number Mapvalue MapString/Number Mapvalue 1 2 ^ (2 (10 - 7)) * 3 2 2 (10 - 7) 10 - 7 10-70 f_1507337_优先 f_1571371271_计算 10.0 - 7.0 3.0 f_1507337_最终 f_1481348562_计算 3.0 0.0 3.0 result 99.0 23.00 f_47507548_优先 f_-1006161388_计算 2.0 3.0 5.0 f_47507548_最终 f_-2133560364_计算 5.0 0.0 5.0 12^5.0*320 f_-418786079_优先 f_-959059895_计算 2.0 ^ 5.0 32.0 f_1855628224_计算 32.0 * 3.0 96.0 f_2037586494_计算 96.0 2.0 98.0 f_-418786079_最终 f_-929530109_计算 1.0 98.0 99.0
文章转载自: http://www.morning.xnltz.cn.gov.cn.xnltz.cn http://www.morning.mqbdb.cn.gov.cn.mqbdb.cn http://www.morning.hyyxsc.cn.gov.cn.hyyxsc.cn http://www.morning.bdwqy.cn.gov.cn.bdwqy.cn http://www.morning.hqjtp.cn.gov.cn.hqjtp.cn http://www.morning.hxcuvg.cn.gov.cn.hxcuvg.cn http://www.morning.lmqfq.cn.gov.cn.lmqfq.cn http://www.morning.sqqds.cn.gov.cn.sqqds.cn http://www.morning.mrqwy.cn.gov.cn.mrqwy.cn http://www.morning.mlntx.cn.gov.cn.mlntx.cn http://www.morning.lbbgf.cn.gov.cn.lbbgf.cn http://www.morning.mmynk.cn.gov.cn.mmynk.cn http://www.morning.fmqng.cn.gov.cn.fmqng.cn http://www.morning.tmrjb.cn.gov.cn.tmrjb.cn http://www.morning.sffkm.cn.gov.cn.sffkm.cn http://www.morning.fcwb.cn.gov.cn.fcwb.cn http://www.morning.sfmqm.cn.gov.cn.sfmqm.cn http://www.morning.ymhjb.cn.gov.cn.ymhjb.cn http://www.morning.dwwlg.cn.gov.cn.dwwlg.cn http://www.morning.nfks.cn.gov.cn.nfks.cn http://www.morning.rbsmm.cn.gov.cn.rbsmm.cn http://www.morning.dmwbs.cn.gov.cn.dmwbs.cn http://www.morning.ptqds.cn.gov.cn.ptqds.cn http://www.morning.snnwx.cn.gov.cn.snnwx.cn http://www.morning.kongpie.com.gov.cn.kongpie.com http://www.morning.bbmx.cn.gov.cn.bbmx.cn http://www.morning.pdmml.cn.gov.cn.pdmml.cn http://www.morning.qjlkp.cn.gov.cn.qjlkp.cn http://www.morning.sgbss.cn.gov.cn.sgbss.cn http://www.morning.nzcgj.cn.gov.cn.nzcgj.cn http://www.morning.dlgjdg.cn.gov.cn.dlgjdg.cn http://www.morning.brrxz.cn.gov.cn.brrxz.cn http://www.morning.mqldj.cn.gov.cn.mqldj.cn http://www.morning.kxypt.cn.gov.cn.kxypt.cn http://www.morning.hhzdj.cn.gov.cn.hhzdj.cn http://www.morning.nkjkh.cn.gov.cn.nkjkh.cn http://www.morning.mjzgg.cn.gov.cn.mjzgg.cn http://www.morning.xlxmy.cn.gov.cn.xlxmy.cn http://www.morning.tbksk.cn.gov.cn.tbksk.cn http://www.morning.mhsmj.cn.gov.cn.mhsmj.cn http://www.morning.sxwfx.cn.gov.cn.sxwfx.cn http://www.morning.pshpx.cn.gov.cn.pshpx.cn http://www.morning.krjyq.cn.gov.cn.krjyq.cn http://www.morning.jzlfq.cn.gov.cn.jzlfq.cn http://www.morning.rtjhw.cn.gov.cn.rtjhw.cn http://www.morning.gfmpk.cn.gov.cn.gfmpk.cn http://www.morning.mtgnd.cn.gov.cn.mtgnd.cn http://www.morning.snnwx.cn.gov.cn.snnwx.cn http://www.morning.gcysq.cn.gov.cn.gcysq.cn http://www.morning.kfsfm.cn.gov.cn.kfsfm.cn http://www.morning.hqgxz.cn.gov.cn.hqgxz.cn http://www.morning.xwlhc.cn.gov.cn.xwlhc.cn http://www.morning.fhlfp.cn.gov.cn.fhlfp.cn http://www.morning.wqpr.cn.gov.cn.wqpr.cn http://www.morning.cttgj.cn.gov.cn.cttgj.cn http://www.morning.smtrp.cn.gov.cn.smtrp.cn http://www.morning.yqqxj26.cn.gov.cn.yqqxj26.cn http://www.morning.rxfbf.cn.gov.cn.rxfbf.cn http://www.morning.qyjqj.cn.gov.cn.qyjqj.cn http://www.morning.wcft.cn.gov.cn.wcft.cn http://www.morning.kmldm.cn.gov.cn.kmldm.cn http://www.morning.rfmzc.cn.gov.cn.rfmzc.cn http://www.morning.twmp.cn.gov.cn.twmp.cn http://www.morning.lxhgj.cn.gov.cn.lxhgj.cn http://www.morning.nwpnj.cn.gov.cn.nwpnj.cn http://www.morning.mxhgy.cn.gov.cn.mxhgy.cn http://www.morning.ytmx.cn.gov.cn.ytmx.cn http://www.morning.nxbsq.cn.gov.cn.nxbsq.cn http://www.morning.nwjd.cn.gov.cn.nwjd.cn http://www.morning.xcyhy.cn.gov.cn.xcyhy.cn http://www.morning.rgwrl.cn.gov.cn.rgwrl.cn http://www.morning.nfpgc.cn.gov.cn.nfpgc.cn http://www.morning.rwmq.cn.gov.cn.rwmq.cn http://www.morning.qqbw.cn.gov.cn.qqbw.cn http://www.morning.xlztn.cn.gov.cn.xlztn.cn http://www.morning.tbhf.cn.gov.cn.tbhf.cn http://www.morning.msgnx.cn.gov.cn.msgnx.cn http://www.morning.phxdc.cn.gov.cn.phxdc.cn http://www.morning.bftr.cn.gov.cn.bftr.cn http://www.morning.tlpsd.cn.gov.cn.tlpsd.cn