[java]代码库
package day04;
import java.util.Scanner;
//随机加法运算器
public class Addition {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int score = 0; //得分
for(int i=1;i<=10;i++){ //10次
int a = (int)(Math.random()*100); //加数a
int b = (int)(Math.random()*100); //加数b
int result = a+b; //存结果
System.out.println("("+i+")"+a+"+"+b+"=?"); //1.出题
System.out.println("算吧!");
int answer = scan.nextInt(); //2.答题
if(answer==-1){ //3.判题
System.out.println("下次再来吧!");
break;
}
if(answer==result){
System.out.println("答对了");
score += 10; //答对1题加10分
}else{
System.out.println("答错了");
}
}
System.out.println("score="+score);
}
}
by: 发表于:2017-08-29 16:24:39 顶(0) | 踩(0) 回复
??
回复评论