zoukankan      html  css  js  c++  java
  • 结对项目---简单四则运算

    结对对象:陈秋月  学号:2013110404  博客地址:http://www.cnblogs.com/Issing/

    双方贡献比例:1:1

    结对编程照片:

    源代码:

    package com.hrr.arithmetic;

    import java.util.Random;
    import java.util.Scanner;

    public class ArithmeticTest {
    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    Random random = new Random();
    int num = 0;// 控制题目数量
    int opA, opB;// 定义两个操作数
    int result = 0;
    Boolean flag = true;
    String[] operator = { "+", "-", "×", "÷" };
    // String problem = null;

    while (num < 30) {
    opA = random.nextInt(100);
    opB = random.nextInt(100);
    String op;
    op = operator[random.nextInt(operator.length)];
    while (flag) {
    if (op == "÷") {
    while (opA < opB || opB == 0 || opA % opB != 0) {
    opA = random.nextInt(100);
    opB = random.nextInt(100);
    }
    result = opA / opB;
    } else if (op == "-") {
    while (opA < opB) {
    opA = random.nextInt(100);
    opB = random.nextInt(100);
    }
    result = opA - opB;
    } else if (op == "+") {
    result = opA + opB;
    } else if (op == "×") {
    result = opA * opB;
    }
    if (result > 100) {
    opA = random.nextInt(100);
    opB = random.nextInt(100);
    op = operator[random.nextInt(operator.length)];
    flag = true;
    } else {
    flag = false;
    }
    }
    flag = true;
    num++;
    System.out.println(num + "、 " + opA + op + opB + "=" + " ");

    }

    }
    }

    运行结果:

    点滴成就 学习时间 新编写代码行数 博客量 学到知识点
    第一周 11 0 0 软件工程
    第二周 12 0 1 软件工程
    第三周 12 0 1 软件工程
    第四周 12 100 1 软件工程
    第五周 11 0 0 软件工程
    第六周 11 210 0 编译原理
    第七周 13 56 1 软件工程
  • 相关阅读:
    nginx的url重写[rewrite规则和参考]
    nginx虚拟主机配置
    redhat 5下源码安装nginx服务
    apache服务器参数设置
    java实现全排列
    自定义栈类型,具有找到站内最小元素的min函数 ,且min(),pop(),push()函数的时间复杂度为O(1)
    如何学习一门新语言
    2018 中印诗人分享会
    C语言细节注意
    C++ vector 多次删除第一个元素
  • 原文地址:https://www.cnblogs.com/hrrpcy/p/5368285.html
Copyright © 2011-2022 走看看