1 设计思路:
生成四个随机数,然后通过0,1,2,3表示加减乘除四种情况,在每一个运算形式下,通过比较前两个随机数相除和后两个随机数相除是否有余数来调整输出方式即可。还有就是通过for循环来实现需要的次数。
2源程序代码:
public class sizeyunsuan{
public static void main(String[]args){
for (int i=0;i<30;i++){
int num1 = (int)(Math.random() * 100 +0);
int num2 = (int)(Math.random() * 100+0 );
int num3 = (int)(Math.random() * 100+0 );
int num4 = (int)(Math.random() * 100+0 );
int n=num1%4;
switch(n){
case 0:
if(num1%num2==0&&num3%num4==0){
System.out.println(num1/num2+"+"+num3/num4+"=");
}
if(num1%num2==0&&num3%num4!=0){
System.out.println(num1/num2+"+"+num3+"/"+num4+"=");}
if(num1%num2!=0&&num3%num4==0){
System.out.println(num1+"/"+num2+"+"+num3/num4+"=");}
if(num1%num2!=0&&num3%num4!=0){
System.out.println(num1+"/"+num2+"+"+num3+"/"+num4+"=");}
case 1:
if(num1%num2==0&&num3%num4==0){
System.out.println(num1/num2+"-"+num3/num4+"=");}
if(num1%num2==0&&num3%num4!=0){
System.out.println(num1/num2+"-"+num3+"/"+num4+"=");}
if(num1%num2!=0&&num3%num4==0){
System.out.println(num1+"/"+num2+"-"+num3/num4+"=");}
if(num1%num2!=0&&num3%num4!=0){
System.out.println(num1+"/"+num2+"-"+num3+"/"+num4+"=");}
case 2:
if(num1%num2==0&&num3%num4==0){
if(num1%num2==0&&num3%num4!=0){
System.out.println(num1/num2+"*"+num3+"/"+num4+"=");}
if(num1%num2!=0&&num3%num4==0){
System.out.println(num1+"/"+num2+"*"+num3/num4+"=");}
if(num1%num2!=0&&num3%num4!=0){
System.out.println(num1+"/"+num2+"*"+num3+"/"+num4+"=");}
case 3:
if(num1%num2==0&&num3%num4==0){
System.out.println(num1/num2+"/"+num3/num4+"=");}
if(num1%num2==0&&num3%num4!=0){
System.out.println(num1/num2+"/"+num3+"/"+num4+"=");}
if(num1%num2!=0&&num3%num4==0){
System.out.println(num1+"/"+num2+"/"+num3/num4+"=");}
if(num1%num2!=0&&num3%num4!=0){
System.out.println(num1+"/"+num2+"/"+num3+"/"+num4+"=");}
}
}
}
}
3 程序结果截图:
4 未按时完成的原因:
由于一段时间未复习,导致很多知识的遗忘,很多内容忘记,导致自己练习未按时完成。