1 Star 0 Fork 0

BESTI.IS.JAVA2018/20165315ch1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
CreatOpNum.java 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
20165315 提交于 7年前 . 随机生成操作数
import java.util.Random;
public class CreatOpNum {
Rational opNum = new Rational();
Random random = new Random();
String opnumFile = "";
String opnumPri = "";
int flag;
CreatOpNum(int flag1) {
flag = flag1;
int a = random.nextInt(1000);
opNum.setNumerator(a);
if (flag1 == 1) {//是分数
int b = random.nextInt(1000);
while (b == 0) {
b = random.nextInt(1000);
}
opNum.setDenominator(b);
} else {//不是分数
opNum.setDenominator(1);
}
}
public void getOpNumFile() {
opnumFile = opNum.getNumerator() + "/" + opNum.getDenominator();
}
public void getOpNumPri() {
if (flag == 0) {
opnumPri = opNum.getNumerator() + "";//输出整数
} else if (opNum.getNumerator() > opNum.getDenominator()) {//假分数
int n = opNum.getNumerator() / opNum.getDenominator();
int m = opNum.getNumerator() % opNum.getDenominator();
opnumPri = n + "'" + m + "/" + opNum.getDenominator();
} else {
opnumPri = opNum.getNumerator() + "/" + opNum.getDenominator();
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/BESTI-IS-JAVA-2018/ch1.git
git@gitee.com:BESTI-IS-JAVA-2018/ch1.git
BESTI-IS-JAVA-2018
ch1
20165315ch1
master

搜索帮助