zoukankan      html  css  js  c++  java
  • 结对合作 出题并判断对错

     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 }

        结对组合:林莉  和  宫丽君

  • 相关阅读:
    Mac 删除Openfire
    FMDB使用
    豆瓣restful api 状态和错误码
    豆瓣开放api
    常用文字配色方案
    电商网站参考
    HP后端跨域HEADER头
    PHP统计 图表实现方法
    PHP 全过程教程和测试网
    Ajax技术在购物车中的应用(PHP篇)
  • 原文地址:https://www.cnblogs.com/linliaimeili/p/5847483.html
Copyright © 2011-2022 走看看