import java.util.Random;
import java.util.Scanner;
public class Num {
public static void main(String[] args) {
System.out.println("练习题数:");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println("---------------------");
int c =0;
int result = 0;//计算结果
int count = 0;//正确题数
for (int j = 0; j <n; j++) {
Random random = new Random();//运算数
int a = random.nextInt(100);
int b = random.nextInt(100);
char[] ch = {‘+‘,‘-‘,‘*‘,‘/‘};
Random ran = new Random();//运算符
int i = ran.nextInt(ch.length);
switch(i){
case 0:
System.out.println(a+"+"+b+"= ?");
result=a+b;
c++;
break;
case 1:
System.out.println(a+"-"+b+"= ?");
result=a-b;
c++;
break;
case 2:
System.out.println(a+"*"+b+"= ?");
result=a*b;
c++;
break;
case 3:
System.out.println(a+"/"+b+"= ?");
//除法运算结果取整
float x = a;
float y = b;
if(y!=0){
result =(int)(x/y);
}
else{
System.out.println("分母有误,跳过上题 ");
break;
}
c++;
break;
}
System.out.println("请输入答案: ");
float an = sc.nextFloat();//输入计算结果
if(an==result){
System.out.println("你真棒o( ̄▽ ̄)d -------");
count++;
}else{
System.out.println("回答错误"+"--正确结果为: "+result+"---继续努力ヾ(?°?°?)??------");
}
}
System.out.println("输出的题数共:"+c+"------共答对"+count+"道题");
}
}