四则运算—结对编程
开发人员:陈佳俊,罗锐鑫
程序描述:随机生成1~100的四则运算
思路:1:定义一个四则运算符数组
2:生成1~100的随机数
3:生成运算项的个数
4:生成运算符
5:完成1~100的四则运算
贡献值:两个人的贡献值是均值的。程序的构想和编写都由两人共同参与编写。
源代码:
/*
* 项目:四则运算
* 作者:陈佳俊,罗锐鑫
* 时间:2017-4-4
*
* */
public class fx {
public static void main(String[] args) {
//运算符号数组
String simple[] = {"+","-","*","/"};
for(int j = 0;j<30;j++){
//生成1~100之间的随机数
String str = String.valueOf((int) (Math.random()*100+1));
//生成运算项的个数
int count = (int) (Math.random()*3+2);
for(int i = 0;i < count-1;i++){
//生成运算项
int a = (int) (Math.random()*100+1);
//生成运算符
int b = (int) (Math.random()*4);
str += simple[b]+String.valueOf(a);
}
System.out.println(str+"=");
}
}
}
截图:
照片: