Posted In: Java Core, String
How to parse a mathematical expression given as a string – using Bean Shell
Evaluating a math expression given in string form
Maven beanshell
<dependency> <groupId>org.beanshell</groupId> <artifactId>bsh</artifactId> <version>2.1b5</version> </dependency> <repository> <id>boundless</id> <url>http://repo.boundlessgeo.com/main/</url> </repository>
beanshell import
package com.example.mathexpression;
import org.junit.Test;
import bsh.Interpreter;
public class MathExpression {
@Test
public void evaluate1() throws Exception {
System.out.println("\nevaluate1() start");
Interpreter interpreter = new Interpreter();
interpreter.eval("result = 5+4*(7-15)");
System.out.println(interpreter.get("result"));
}
}
Tags: String mathematical expression
- Apache (13)
- Build Tools (2)
- Gradle (2)
- Caching (1)
- cpanel (1)
- cURL (1)
- Database (7)
- Hibernate (5)
- Java Core (38)
- Java Script (15)
- Bootstrap (1)
- File Upload (7)
- jQuery (3)
- React (3)
- JEE (13)
- JSON (41)
- GSON (13)
- Jackson 1X (1)
- Jackson 2X (12)
- jsoniter (1)
- Logging (2)
- Apache Commons Logging (1)
- Apache Log4J (1)
- Logback (1)
- SLF4J (1)
- MongoDB (1)
- OS (1)
- Linux (1)
- Security (5)
- Server (4)
- Tomcat (4)
- Service (2)
- Micro (2)
- Spring (46)
- Pattern (2)
- Spring Boot (20)
- Spring Data (4)
- Spring MVC (8)
- Spring REST (13)
- Spring Security (7)
- Testing (11)
- XML (5)
- JDOM XML Parser (1)