• 随机生成思则运算2


    package fee;
    
    import java.util.*;
    import java.util.Random;
    
    public class pp {
        static Scanner in = new Scanner(System.in);
        static Random r = new Random();
    
        public static void main(String[] args) {
            System.out.println("答对了一提获得5分");
            System.out.println("输入题目数量:");
            int x = in.nextInt();
            int fenshu=0;
    
            // int r1=r.nextInt(100);
            // int r2=r.nextInt(100);
            System.out.println("输入1表示加法2表示减3表示乘4表示除:");
            int y = in.nextInt();
            switch (y) {
            case 1:
                for (int i = 0; i < x; i++) {
                    double r1 = r.nextInt(100);
                    double r2 = r.nextInt(100);
                    System.out.println(r1 + "+" + r2 + "=");
                    double a = in.nextInt();
                    double b = r1+r2;
                    if(a==b){System.out.println("答对了!获得5分");fenshu=fenshu+5;}
                    else{System.out.println("打错了,正确答案为"+b);}
                    System.out.println("你当前的的分数为"+fenshu);
                }
                break;
            case 2:
                for (int i = 0; i < x; i++) {
                    double r1 = r.nextInt(100);
                    double r2 = r.nextInt(100);
                    System.out.println(r1 + "-" + r2 + "=");
                    double a = in.nextInt();
                    double b = r1-r2;
                    if(a==b){System.out.println("答对了!获得5分");fenshu=fenshu+5;}
                    else{System.out.println("打错了,正确答案为"+b);}
                    System.out.println("你当前的的分数为"+fenshu);
                }
                break;
            case 3:
                for (int i = 0; i < x; i++) {
                    double r1 = r.nextInt(100);
                    double r2 = r.nextInt(100);
                    System.out.println(r1 + "*" + r2 + "=");
                    double a = in.nextInt();
                    double b = r1*r2;
                    if(a==b){System.out.println("答对了!获得5分");fenshu=fenshu+5;}
                    else{System.out.println("打错了,正确答案为"+b);}
                    System.out.println("你当前的的分数为"+fenshu);
                }
                break;
            case 4:
                for (int i = 0; i < x; i++) {
                    double r1 = r.nextInt(100);
                    double r2 = r.nextInt(100);
                    System.out.println(r1 + "/" + r2 + "=");
                    double a = in.nextInt();
                    double b = r1/r2;
                    if(a==b){System.out.println("答对了!获得5分");fenshu=fenshu+5;}
                    else{System.out.println("打错了,正确答案为"+b);}
                    System.out.println("你当前的的分数为"+fenshu);
                }
                break;
            }
            System.out.println("你获得的分数为"+fenshu);
    
        }
    
    }

    真分数功能没有实现


  • 相关阅读:
    AOP
    关于zookeeper部署的个数
    Zookeeper 简介
    Java 正则表达式
    面试记录
    面试题
    Spring Framework官方文档翻译(中英文版)
    java知识巩固
    mysql sql记录
    redis入门
  • 原文地址:https://www.cnblogs.com/liwenzhong/p/4381581.html
Copyright © 2020-2023  润新知