import java.util.Scanner;
public class AddCode {
public static void main(String[] args){
System.out.println("即将开始10次加法测试。。。");
Scanner sc = new Scanner(System.in);
//用于记载分数
int score = 0;
//构建10次循环
for(int i = 1;i<=10;i++){
//随机生成两个加数
int a = (int)(Math.random()*100);
int b = (int)(Math.random()*100);
int result = a+b;
//输出需要计算的加法表达式
System.out.println("("+i+")."+a+"+"+b+"=?");
System.out.println("请输入答案(输入-1退出):");
//读入结果
int answer = sc.nextInt();
//判断对错
if(answer == -1){
break;
}else if(answer != result){
System.out.println("Error");
continue;
}else{
score += 10;
System.out.println("Correct!");
}
}
sc.close();
System.out.println("此次测验的结果:"+score);
}
}
转载于:https://www.cnblogs.com/ls00/p/6924339.html