import java.lang.*; import java.util.Scanner; public class Kq { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int a, b, c; int systemanswer = 0; int useranswer = 0; int rightnumber = 0; char op = 0; System.out.println("欢迎使用自动生成小学四则运算程序,本程序每一次出十道题,用户做对6题或6题以上即退出程序"); do { for (int i = 1; i <= 10; i++) { a = 1 + (int) (Math.random() * 10); b = 1 + (int) (Math.random() * 10); c = 1 + (int) (Math.random() * 4); switch (c) { case 1: op = '+'; systemanswer = a + b; break; case 2: op = '-'; systemanswer = a - b; break; case 3: op = '*'; systemanswer = a * b; break; case 4: op = '/'; systemanswer = a / b; break; default: System.out.printf("无效"); } System.out.printf("%d%c%d=? ", a, op, b); Scanner in = new Scanner(System.in); useranswer = in.nextInt(); if (useranswer == systemanswer) { System.out.printf("right! "); rightnumber++; } else { System.out.printf("wrong! "); } } System.out.printf("总分%d ", rightnumber * 10); System.out.printf("百分比%d%% ", rightnumber * 10); if (rightnumber * 10 < 60) { System.out.printf("再来一遍 "); rightnumber = 0; } } while (rightnumber * 10 < 60); } }