7-5=2,1+4=5,2*9=16,2*7=14,5-5=0,7+7=14,6+2=9,共答7正确5错2!这些算术式有
1个回答

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 就好