1 PackageCom.java.sizeyunsuan;2 3 Public classLianxi {4 String F ()5 {6 intI= (int) (Math.random () *10);7 intJ= (int) (Math.random () *10);8 if(i>=j)9 {Ten inttemp=i; OneI=J; Aj=temp; - } - return(i+ "/" +j); the } - Public Static voidMain (string[] args) - { - String A, b; + intK; -Lianxi lianxi=NewLianxi (); + for(intn=0;n<30;n++) A { atA=lianxi.f (); -b=lianxi.f (); - intI= (int) (Math.random () *100); - intJ= (int) (Math.random () *100); - Switch((int) (Math.random ())) - { in Case0: -K= (int) (Math.random ()); to if(k==0) +System.out.println (i+ "+" +j+ "="); - Else if(k==1) theSystem.out.println (A + "+" +j+ "="); * Else if(k==2) $System.out.println (b + "+" +a+ "=");Panax Notoginseng Break; - Case1: theK= (int) (Math.random ()); + if(i<j) A { the inttemp=i; +I=J; -j=temp; $ } $ if(k==0) -System.out.println (i+ "-" +j+ "="); - Else if(k==1) theSystem.out.println (j+ "-" +a+ "="); - Else if(k==2)WuyiSystem.out.println (b + "-" +a+ "="); the Break; - Case2: WuK= (int) (Math.random ()); - if(k==0) AboutSYSTEM.OUT.PRINTLN (i+ "*" +j+ "="); $ Else if(k==1) -System.out.println (A + "*" +j+ "="); - Else if(k==2) -System.out.println (b + "*" +a+ "="); A Break; + Case3: the while(j==0) -J= (int) (Math.random () *100); $System.out.println (i+ "/" +j+ "="); the Break; the } the } the } -}
1. Design ideas: This topic is randomly generated 30 arithmetic, first to generate a random number, I first wrote a function to randomly generate a true fraction, and then call this function in the main function to get its return value, and then use the random () to produce two two-bit random integers, Then, the Swich branch structure was used to implement subtraction, randomly generating 0,1,2,3, representing subtraction respectively.
Note: (1) Taking into account that pupils have not learned negative numbers, so in the subtraction, if the presence of minuend greater than the meiosis, will be two number exchange, and then subtraction;
(2) Considering that the divisor can not be 0, if the divisor is 0, then generate a random number, using while loop;
(3) in each operation and the IF-ELSE structure is divided into a variety of situations, in which the division is too many and complex, not one after another, will be improved in the future.
2. Operation Result:
3. Reasons for not completing the class:
(1) root cause: to C,c++,java and other languages are not skilled, forget how to use the random function, even the most basic grammar have forgotten, said ashamed!
(2) Objective reason: the use of programming software is not skilled, in the VS2010 to create C + + project has a problem, delayed a long time!
This procedure is still a lot of shortcomings, I hope you criticize the advice!
Software engineering after-work--a randomly generated 30-channel arithmetic written in Java