1.今日课堂练习
二柱一下打印出好多份不同的题目,让孩子做了。老师看了作业之后,对二柱赞许有加。别的老师闻讯, 问二柱能否扩大他的影响力,编个软件,给二年级到四年级都用,多了一些小小的要求:
1、题目避免重复(第二阶段);
2、可定制(数量/打印方式):输入大的数量值,测试一下系统是否崩溃,反向查找系统是否优化的余地;
3、定制操作数的个数:
4、定制是否有乘除法
5、定制是否有括号(随机加入)
6 、定制数值范围(确定操作数的取值范围)
1 import java.util.Scanner; 2 import java.util.Random; 3 public class count_number { 4 static int number=1000,i=0; 5 static int []a1=new int[number]; 6 static int []a2=new int[number]; 7 public static boolean judge() { 8 boolean y=false; 9 if(i!=0) { 10 if(a1[i]==a1[i-1]&&a2[i]==a2[i]) 11 y=true; 12 else 13 y=false; 14 } 15 return y; 16 } 17 public static void birth() { 18 a1[i]=(int)(Math.random()*100); 19 a2[i]=(int)(Math.random()*100); 20 } 21 public static void main(String []args) { 22 int sum; 23 boolean flag=true; 24 int s; 25 String m="s"; 26 Scanner in=new Scanner(System.in); 27 System.out.println("请输入题目数量:"); 28 sum=in.nextInt(); 29 30 for(i=0;i<sum;i++) { 31 birth(); 32 s=(int)(Math.random()*4); 33 if(s==0) { 34 m="+"; 35 flag=judge(); 36 if(flag) { 37 birth(); 38 } 39 } 40 if(s==1) { 41 42 m="-"; 43 flag=judge(); 44 if(flag) { 45 birth(); 46 } 47 } 48 if(s==2) { 49 if(a1[i]*a2[i]<100) { 50 51 m="*"; 52 flag=judge(); 53 if(flag) { 54 birth(); 55 } 56 } 57 else { 58 birth(); 59 } 60 61 } 62 if(s==3) { 63 m="/"; 64 flag=judge(); 65 if(flag) { 66 birth(); 67 } 68 } 69 70 System.out.println(a1[i]+m+a2[i]+"="); 71 } 72 } 73 74 }
测试截图: