基本功能:

  1. 自动生成一百以内的加法算式,并自动判断是否正确,如果不正确则给出正确答案
  2. 自动生成一百以内的减法算式,并自动判断是否正确,如果不正确则给出正确答案
  3. 自动生成一百以内的乘法算式,并自动判断是否正确,如果不正确则给出正确答案
  4. 自动生成一百以内的除法算式,并自动判断是否正确,如果不正确则给出正确答案(功能优化不够完善,鉴于本人数学水平太差,不知道应该怎么优化了,有建议的可以留言!!)
  5. 可以根据需要选择要生成的算式类型和数量
    代码中不包含图形界面,只有控制台输出

代码实现:

package cc.wuque;

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true){
int x, y, z;
System.out.println("****欢迎使用口算练习系统****");
System.out.println("1、加法练习");
System.out.println("2、减法练习");
System.out.println("3、乘法练习");
System.out.println("4、除法练习");
System.out.print("请选择需要练习的序号:");
z = sc.nextInt();
System.out.print("请选择需要练习的次数:");

    int count = sc.nextInt();
    if (z == 1){
        System.out.print("您选择了加法练习");
        while(count != 0 ){
            System.out.println("当前剩余练习次数:" + count);
            x = (int) (Math.random() * 50);
            y = (int) (Math.random() * 50);
            System.out.print(x + "+" + y + "=");
            int result = sc.nextInt();
            if (result != (x + y)){
                System.out.println("回答错误,正确答案:" + (x + y));
            }else {
                System.out.println("回答正确");
            }
            count--;
        }

    }else if (z == 2){
        System.out.print("您选择了减法练习");
        while (count != 0){
            System.out.println("当前剩余练习次数:" + count);
            x = (int) (Math.random() * 100);
            y = (int) (Math.random() * 100);
            while(y > x){
                x = (int) (Math.random() * 100);
            }
            System.out.print(x + "-" + y + "=");
            int result = sc.nextInt();
            if (result != (x - y)){
                System.out.println("回答错误,正确答案:" + (x - y));
            }else {
                System.out.println("回答正确");
            }
            count--;
        }
    }else if (z == 4){
        System.out.println("您选择了除法练习");
        System.err.println("除法的运算结果只能为整数!!!");
        while (count != 0){
            System.out.println("当前剩余练习次数:" + count );

            x = (int) (Math.random() * 100);
            y = (int) (Math.random() * 10);
            if (y == 0){
                y = (int) (Math.random() * 10);
            }
            System.out.print(x + " / " + y + "=");
            System.out.println();
            System.out.println();
            /*String remove = String.valueOf((Integer)(x / y));*/
            /*String more = String.valueOf((Integer) (x % y));*/
            int remove = x / y;
            int more = x % y;
            String s;
            Double DoubleResult = null;
            int result = 0;
            if (more == 0){
                s = String.valueOf(remove);
                result = sc.nextInt();
            }else {
                s = remove + "." + more;
                DoubleResult = sc.nextDouble();
            }
            String StrResult = result + "";
            String StrDoubleResult = DoubleResult + "";

            /*System.out.println("result:" + result);
            System.out.println("s:" + s);
            System.out.println("remove:" + remove);
            System.out.println("more:" + more);*/
            if (s.equals(StrResult)){
                System.out.println("回答正确");
            }else if (s.equals(StrDoubleResult)){
                System.out.println("回答正确");
            }else {
                System.out.println("回答错误,正确答案:" + s);
            }
            count--;
        }
    }else if (z == 3){
        System.out.print("您选择了乘法练习");
        while (count != 0){
            System.out.println("当前剩余练习次数:" + count);
            x = (int) (Math.random() * 10);
            y = (int) (Math.random() * 10);
            System.out.print(x + " x " + y + "=");

            int result = sc.nextInt();
            if (result != (x * y)){
                System.out.println("回答错误,正确答案:" + (x * y));
            }else {
                System.out.println("回答正确");
            }
            count--;
        }
    }else {
        System.out.println("您选择的序号有误或非法,请重新输入!!!!  ");
    }
}
}
}
最后修改:2022 年 01 月 14 日 11 : 07 AM
如果觉得我的文章对你有用,请随意赞赏