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

结对合作 出题并判断对错

时间:2016-09-07 01:02:34      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

 1 package tools;
 2 
 3 import java.util.Random;
 4 import java.util.Scanner;
 5 
 6 public class problem {
 7 
 8     public static void main(String[] args) {
 9         /**
10          * 一共循环10次。
11          */
12         int rightNum = 0;//正确次数
13         int wrongNum = 0;//错误次数
14         for (int i =1; i <= 10; i++) {
15             System.out.println("请计算第" + i + "道题:");// 做到第几题,循环输出
16             int number1 =(int) (Math.random() * 10);
17             int number2 =(int) (Math.random() * 10);
18             Random num = new Random();// 生成随机运算符
19             int index = num.nextInt(3) + 1;
20             char[] fuhaos = { ‘+‘, ‘-‘, ‘*‘, ‘/‘ };
21             String fuhao = String.valueOf(fuhaos[index]);
22             Scanner scan = new Scanner(System.in);
23             if (fuhao.equals("+")) { // 进行加法运算
24                 System.out.println(number1 + "+" + number2 + "=");
25                 int input = scan.nextInt();
26                 int sum = number1 + number2;
27                 if (sum==input) {
28                     System.out.println("正确");
29                     rightNum++;
30                 } else {
31                     System.out.println("错误");
32                     wrongNum++;
33                 }
34                 System.out.println("正确答案是:" + sum);
35             }else if (fuhao.equals("-")) { // 进行减法运算
36                 System.out.println(number1 + "-" + number2 + "=");
37                 int input = scan.nextInt();
38                 int sum = number1 - number2;
39                 if (sum==input) {
40                     System.out.println("正确");
41                     rightNum++;
42                 } else {
43                     System.out.println("错误");
44                     wrongNum++;
45                 }
46                 System.out.println("正确答案是:" + sum);
47             }else if (fuhao.equals("*")) { // 进行乘法运算
48                 System.out.println(number1 + "*" +number2 + "=");
49                 int input = scan.nextInt();
50                 int sum = number1 * number2;
51                 if (sum==input) {
52                     System.out.println("正确");
53                     rightNum++;
54                 } else {
55                     System.out.println("错误");
56                     wrongNum++;
57                 }
58                 System.out.println("正确答案是:" + sum);
59             }else {                     // 进行除法运算
60                 System.out.println(number1 + "/" + number2 + "=");
61                 int input = scan.nextInt();
62                 int sum = number1 / number2;
63                 if (sum==input) {
64                     System.out.println("正确");
65                     rightNum++;
66                 } else {
67                     System.out.println("错误");
68                     wrongNum++;
69                 }
70                 System.out.println("正确答案是:" + sum);
71             }
72         }
73         System.out.println("做对" + rightNum + "题");
74         System.out.println("做错" + wrongNum + "题");
75     }
76 }

    结对组合:林莉  和  宫丽君

结对合作 出题并判断对错

标签:

原文地址:http://www.cnblogs.com/linliaimeili/p/5847483.html

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