码迷,mamicode.com
首页 > 其他好文 > 详细

随机生成思则运算2

时间:2015-03-31 19:27:06      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:

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

    }

}

真分数功能没有实现

技术分享

 

随机生成思则运算2

标签:

原文地址:http://www.cnblogs.com/liwenzhong/p/4381581.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!