package chuti;
import java.util.Scanner;
public class Demo {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
for (int i = 1; i <=30; i++) {
int a = (int) Math.round(Math.random() * 100);
int b = (int) Math.round(Math.random() * 100);
int m= (int) Math.round(Math.random() * 3);
switch(m)
{
case 0:
System.out.println(i+": "+a+"/"+b+"=");
int c0 = in.nextInt();
System.out.println(i+": "+a+"/"+b+"="+c0);
int c6=a/b;
if (c0 == a/b) {
System.out.println("正确");
}
else {
System.out.println("错误,正确答案为"+a+"/"+b+"="+c6);
}
break;
case 1:
System.out.println(i+": "+a+"*"+b+"=");
int c1 = in.nextInt();
System.out.println(i+": "+a+"*"+b+"="+c1);
int c5=a*b;
if (c1 == (a*b)) {
System.out.println("正确");
}
else {
System.out.println("错误,正确答案为"+a+"*"+b+"="+c5);
}
break;
case 2:
System.out.println(i+": "+a+"+"+b+"=");
int c2 = in.nextInt();
System.out.println(i+": "+a+"+"+b+"="+c2);
if (c2 == (a+b)) {
System.out.println("正确");
}
else {
System.out.println("错误,正确答案为"+a+"+"+b+"="+a+b);
}
break ;
case 3:
System.out.println(i+": "+a+"-"+b+"=");
int c3 = in.nextInt();
System.out.println(i+": "+a+"-"+b+"="+c3);
int c4=a-b;
if (c3 == (a-b)) {
System.out.println("正确");
}
else {
System.out.println("错误,正确答案为"+a+"-"+b+"="+c4);
}
break ;
}
}
}
}
标签:正确,int,四则运算,System,println,Math,out From: https://www.cnblogs.com/yangsongduo/p/18437029