那种包含括号,和算术运算符还有逻辑运算符的规则引擎的java代码
时间: 2024-01-21 07:18:53 浏览: 24
一个简单的规则引擎可以使用Java中的if-else语句来实现,以下是一个示例代码:
```java
public class RuleEngine {
public static void main(String[] args) {
int a = 10;
int b = 5;
String operator = ">";
if (operator.equals(">")) {
if (a > b) {
System.out.println("a is greater than b");
} else {
System.out.println("a is not greater than b");
}
} else if (operator.equals("<")) {
if (a < b) {
System.out.println("a is less than b");
} else {
System.out.println("a is not less than b");
}
} else if (operator.equals("==")) {
if (a == b) {
System.out.println("a is equal to b");
} else {
System.out.println("a is not equal to b");
}
} else if (operator.equals("!=")) {
if (a != b) {
System.out.println("a is not equal to b");
} else {
System.out.println("a is equal to b");
}
} else {
System.out.println("Invalid operator");
}
}
}
```
此代码可根据输入的两个数字和运算符进行比较,并输出结果。您可以根据需要修改此代码以满足您的规则引擎需求。