自动生成小学四则运算程序

 

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=?\n", a, op, b);

                Scanner in = new Scanner(System.in);

                useranswer = in.nextInt();

                if (useranswer == systemanswer) {

                    System.out.printf("right!\n");

                    rightnumber++;

                } else {

                    System.out.printf("wrong!\n");

                }

            }

            System.out.printf("总分%d\n", rightnumber * 10);

            System.out.printf("百分比%d%%\n", rightnumber * 10);

            if (rightnumber * 10 < 60) {

                System.out.printf("再来一遍\n");

                rightnumber = 0;

            }

        } while (rightnumber * 10 < 60);



    }



}

 自动生成小学四则运算程序

你可能感兴趣的:(四则运算)