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

  • 相关阅读:
    python RabbitMQ队列/redis
    python 协程
    Python 线程
    Python Socket网络编程
    Python 面向对象编程进阶
    Python 面向对象
    python 模块
    Python 迭代器&生成器&装饰器
    Python 集合操作
    Java多态--构造方法的内部方法多态
  • 原文地址:https://www.cnblogs.com/chenruting/p/4408945.html
Copyright © 2011-2022 走看看