Topics requirements: compiling a four operations can subject the code specific requirements: 1, 2 can not be repeated by the subject, the subject can enter any number of printing mode 3 and requires a two-digit multiplication result calculated subject, the subject division results is an integer, calculates the subtraction result is positive subject.
And solving key ideas: This question object key point is that the subject is not a duplication, so the array is used in solving problems, is determined by the stored data out of each question, to determine whether to continue with the next cycle statements, and ultimately out of the title is not repeated.
Code:
1 package SIZEYUNSUAN; 2 import java.util.Random; 3 import java.util.Scanner; 4 public class Num { 5 static Scanner sc=new Scanner(System.in); 6 public static void main(String[] args) { 7 boolean m4; 8 int k=0; 9 Random a=new Random(); 10 System.out.println("请输入出题数目:"); 11 int n1=sc.nextInt(); 12 is System.out.println ( "Please enter the printing mode:" ); 13 is int N2 = sc.nextInt (); 14 int M1 [] = new new int [100000 ]; 15 int M2 [] = new new int [100000 ]; 16 int M3 [] = new new int [100000 ]; . 17 for ( int I = 0; I < N1;) { 18 is M4 = to false ; . 19 int C1 = a.nextInt (100 ); 20 is int C2 = a.nextInt ( 100 ); 21 int c3=a.nextInt(4); 22 for(int j=0;j<k;j++) { 23 if(c1==m1[j]&&c2==m2[j]&&c3==m3[j]) { 24 m4=true; 25 break; 26 } 27 } 28 if(m4) 29 continue; 30 if(c3==0) { 31 System.out.print((i+1)+"."+c1+"+"+c2+"= "); 32 i++; 33 } 34 if(c3==1&&c1>c2) { 35 System.out.print((i+1)+"."+c1+"-"+c2+"= "); 36 i++; 37 } 38 if(c3==1&&c1<=c2){ 39 System.out.print((i+1)+"."+c2+"-"+c1+"= "); 40 i++; 41 } 42 43 if(c3==2) { 44 if(c1*c2<100) { 45 System.out.print((i+1)+"."+c1+"*"+c2+"= "); 46 i++; 47 } 48 else 49 continue; 50 } 51 if(c3==3) { 52 if(((c2!=0)&&(c1%c2)==0)) { 53 System.out.print((i+1)+"."+c1+"/"+c2+"= "); 54 i++; 55 } 56 else 57 continue; 58 } 59 m1[k]=c1; 60 m2[k]=c2; 61 m3[k]=c3; 62 k=k+1; 63 if(i%n2==0) { 64 System.out.println(""); 65 } 66 } 67 } 68 }