📄 suanshi.java
字号:
package edu.bupt.calculate.example;
//产生随机的四则运算题目,输入答案,判断正误
import java.util.*;
class suanshi {
// 产生随机数//
Random rand = new Random();
// int a=(int)Math.random()*50;
// int b=(int)Math.random()*20;//这样的数每次运行时都是一样的.
// int c=(int)Math.random()*10+1;
// rand.setSeed(long d);
int a = (int) rand.nextInt() / 1000000;
int b = (int) rand.nextInt() / 1000000;
int c = (int) (rand.nextFloat() * 10 + 1);
public static double sum = 0;// 一定要声明为static的,否则后面的SUM就会为0
public suanshi() {
}
char d;
public suanshi(int k) { // 产生运算符号//
if (1 <= c && c <= 3) {
d = '+';
sum = a + b;
} else if (4 <= c && c <= 6) {
d = '-';
sum = a - b;
} else if (7 <= c && c <= 8) {
d = '×';
sum = a * b;
} else {
d = '÷';
sum = a / b;
}
System.out.print("(" + a + ")" + " " + d + " " + "(" + b + ")" + "=");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -