zoukankan      html  css  js  c++  java
  • 第一次作业

    import java.util.*;

    public class calculate {
    public static void main(String[] args) {
    T t=new T();
    }
    }

    class T {
    Scanner sc = new Scanner(System.in);
    Random Ra = new Random();
    char[] cal = { '+', '-', '*', '/' };
    char c;
    int n = 10;
    long startTime;
    long endTime;
    long time;

    T() {
    System.out.print("1:人选 2:机选");
    int choice = sc.nextInt();
    switch (choice) {
    case 1: {
    int right = 0;
    System.out.print("请输入习题数:");
    int user_cho = sc.nextInt();
    startTime = System.currentTimeMillis();
    for (int i = 0; i < user_cho; i++) {
    int index = Ra.nextInt(cal.length);// 生成符号,随机数
    c = cal[index];
    int a = Ra.nextInt(100);
    int b = Ra.nextInt(100);
    if (c == '/' && b == 0) {
    index = Ra.nextInt(cal.length);// 生成符号,随机数
    c = cal[index];
    }
    System.out.printf("%d%c%d ", a, c, b);
    int b1=a+c+b;
    int a1 = sc.nextInt();
    if(a1==b1){System.out.print("答案正确! ");}
    else System.out.printf("答案有误!正确答案是%d ",b1);
    }
    endTime = System.currentTimeMillis();
    time = endTime - startTime;
    int time1 = (int) (time / 1000);
    System.out.printf("一共用了%ds", time1);
    }
    break;
    case 2: {
    startTime = System.currentTimeMillis();
    for (int i = 0; i < n; i++) {
    int index = Ra.nextInt(cal.length);// 生成符号,随机数
    c = cal[index];
    int a = Ra.nextInt(100);
    int b = Ra.nextInt(100);

    System.out.printf("%d%c%d ", a, c, b);
    int a2 = sc.nextInt();
    if(a2==a+c+b){System.out.print("答案正确! ");}
    else System.out.printf("答案有误!正确答案是%d ",a+c+b);
    }
    endTime = System.currentTimeMillis();
    time = endTime - startTime;
    int time1 = (int) (time / 1000);
    System.out.printf("一共用了%ds", time1);
    }
    break;
    }
    }
    }

  • 相关阅读:
    登陆澳洲一周年记
    开源项目:SQL Monitor 3.0.8
    数据处理利器SSIS入门与进阶
    自动输出SQL Server对象依赖列表到EXCEL文件
    .NET开源数据库的前世和今生(上)
    分布式文件快速搜索技术细节分析(开源/并行)
    ROS与ROS2通讯机制的区别
    快速理解ROS2通信
    Linux解决The following packages have unmet dependencies
    ROS 移植到各种平台教程
  • 原文地址:https://www.cnblogs.com/chenruting/p/4408945.html
Copyright © 2011-2022 走看看