增加了验证的功能,其他功能待续……
public static char yunsuan; public static int a; public static int b; public static int result; public char getyunsuan() { return yunsuan; } public int geta() { return a; } public int getb() { return b; } public static void main(String[] args) { for(int i=0;i<30;i++){ //for循环定义题目数量 char [] fu = new char [4]; fu[0] = '/'; fu[1] = '+'; fu[2] = '-'; fu[3] = '*'; yunsuan=fu[new Random().nextInt(4)]; a= new Random().nextInt(100) + 1; b= new Random().nextInt(100) + 1; if(yunsuan=='+') result=a+b; else if(yunsuan== '-') result=a-b; else if(yunsuan=='*') result=a*b; else result=a/b; } } @SuppressWarnings("resource") public String yanzheng() { System.out.print(a+ " "+yunsuan+ " " + b+ " = "); int str = new Scanner(System.in).nextInt(); if(str == result) return "回答正确"; else return "错误,正确答案为"+result; } }