结对项目---简单四则运算

结对对象:陈秋月  学号: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 + "=" + "\n");

}

}
}

 

运行结果:

点滴成就 学习时间 新编写代码行数 博客量 学到知识点
第一周 11 0 0 软件工程
第二周 12 0 1 软件工程
第三周 12 0 1 软件工程
第四周 12 100 1 软件工程
第五周 11 0 0 软件工程
第六周 11 210 0 编译原理
第七周 13 56 1 软件工程
posted @ 2016-04-08 15:25  迷上火山baby  阅读(162)  评论(0编辑  收藏  举报