public static void main(String[] args) {
String test = "7-2=4";
if(test.contains("-")){
String[] o1 = test.split("-");
String[] o2 = o1[1].split("=");
int result = Integer.parseInt(o1[0]) - Integer.parseInt(o2[0]);
if(result == Integer.parseInt(o2[1])){
System.out.println("This Result is True");
}else{
System.out.println("Your answer is wrong.The right Result is :"+result);
}
}else if(test.contains("+")){
String[] o1 = test.split("+");
String[] o2 = o1[1].split("=");
int result = Integer.parseInt(o1[0]) + Integer.parseInt(o2[0]);
if(result == Integer.parseInt(o2[1])){
System.out.println("This Result is True");
}else{
System.out.println("Your answer is wrong.The right Result is :"+result);
}
}else if(test.contains("*")){
String[] o1 = test.split("*");
String[] o2 = o1[1].split("=");
int result = Integer.parseInt(o1[0]) * Integer.parseInt(o2[0]);
if(result == Integer.parseInt(o2[1])){
System.out.println("This Result is True");
}else{
System.out.println("Your answer is wrong.The right Result is :"+result);
}
}else if(test.contains("/")){
String[] o1 = test.split("/");
String[] o2 = o1[1].split("=");
int result = Integer.parseInt(o1[0]) / Integer.parseInt(o2[0]);
if(result == Integer.parseInt(o2[1])){
System.out.println("This Result is True");
}else{
System.out.println("Your answer is wrong.The right Result is :"+result);
}
}
}
你试下.直接把这些式子写成String 就好