四则运算|随机产生三十道计算题
写一个能自动生成30道小学四则运算的软件
package shiyan1;
import java.util.Random;
public class yanzheng {
public static void main(String args[]) {
Random random=new Random();
for(int i=0;i<=30;i++) {
int suiji1 = new Random().nextInt(10);
int suiji2 = new Random().nextInt(10);
if(suiji2==0) {
char[] c2 ={'+','-','*'};
int index2=random.nextInt(c2.length);
System.out.print(suiji1);
System.out.print(c2[index2]);
System.out.print(suiji2);
System.out.print("="+'\n');
}
else {
char[] c1 ={'+','-','*','÷'};
int index1=random.nextInt(c1.length);
System.out.print(suiji1);
System.out.print(c1[index1]);
System.out.print(suiji2);
System.out.print("="+'\n');
}
}
}
}
此小程序比较简单,就是调用了Random random=new Random()这个方法,随机产生十以内的整数,
以及调用字符数组和Random()方法来输出运算符号,将随机数和运算符进行组合输出,生产30道计算题