首页 > 其他 > 详细

四则运算

时间:2016-10-22 00:20:14      阅读:302      评论:0      收藏:0      [点我收藏+]
import java.util.Random;
 import java.util.Scanner;
 
  public class qq {
      public static void main(String[] args) {
          int e = 0, r = 0;
          System.out.println("欢迎来到四则运算测试软件!");
          System.out.println("做题前请认真读题,祝您考试愉快!");
          Random r1 = new Random();
         for (int i = 0; i < 7; i++) {
             int m, n;
             int a, b, c;
             m = r1.nextInt() % 10;
             n = m % 4;
 
             switch (n) {
             case 0:
                 a = new Random().nextInt((int) Math.pow(10, 2)) + 1;
                 b = new Random().nextInt((int) Math.pow(10, 2)) + 1;
                 System.out.println(a + "+" + "" + b + "=?");
                 Scanner x1 = new Scanner(System.in);
                 c = x1.nextInt();
                 if (c != a + b) {
                     e++;
                     System.out.println("回答错误!!");
                 } else {
                     r++;
                     System.out.println("回答正确!!");
                 }
 
                 break;
 
             case 1:
                 a = new Random().nextInt((int) Math.pow(10, 2)) + 1;
                 b = new Random().nextInt((int) Math.pow(10, 2)) + 1;
                 System.out.println(a + "-" + " " + b + " =?");
                 Scanner x2 = new Scanner(System.in);
                 c = x2.nextInt();
                 if (c != a - b) {
                     e++;
                     System.out.println("回答错误!!");
                 } else {
                     r++;
                     System.out.println("回答正确!!");
                 }
 
                 break;
 
             case 2:
                 a = new Random().nextInt((int) Math.pow(10, 2)) + 1;
                 b = new Random().nextInt((int) Math.pow(10, 2)) + 1;
                 System.out.println(a + "*" + " " + b + " " + "=?");
                 Scanner y1 = new Scanner(System.in);
                 c = y1.nextInt();
                 if (c != a * b) {
                     e++;
                     System.out.println("回答错误!!");
                 } else {
                     r++;
                     System.out.println("回答正确!!");
                 }
 
                 break;
 
             case 3:
                 double d;
                 a = new Random().nextInt((int) Math.pow(10, 2)) + 1;
                 b = new Random().nextInt((int) Math.pow(10, 2)) + 1;
                 if (b == 0)
                     b++;
                 System.out.println(a + "/" + " " + b + " " + "=?");
                 Scanner y2 = new Scanner(System.in);
                 d = y2.nextDouble();
                 if (d != (a / b) / 1.00) {
                     e++;
                     System.out.println("回答错误!!");
                 } else {
                     r++;
                     System.out.println("回答正确!!");
 
                 }

                 break;
 
             }
         }
         System.out.println("考试结束!!");
         System.out.println("您一共做了:" + (r + e) + "道题目,其中正确的有" + r + "道,错误的有" + e + "道!");
     }
 }

四则运算

原文:http://www.cnblogs.com/1409030209l/p/5986256.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!