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


    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);
    
        }
    
    }

     

  • 相关阅读:
    mac与ip为什么同时存在
    tcp四次挥手
    tcp三次握手
    GET与POST的区别
    Servlet.service() for servlet [jsp] in context ....错误
    c3p0连接数据库时注意事项
    finalize()及垃圾回收
    composer 安装新包失败的原因之一
    如何使用优酷开放平台获取视频播放列表
    php解析优酷网上的视频资源去广告
  • 原文地址:https://www.cnblogs.com/kangqu/p/4369193.html
Copyright © 2020-2023  润新知