ImportJava.util.*; Public classFirst { Public Static voidMain (string[] agrs) {Doublea,b,c,d; intCount1=0,count2=0; inti; String[] s={"+","-","*","/"}; Scanner SC=NewScanner (system.in); intop= 0; while(true) {System.out.println ("Select function: \n0. Exit 1. Simple subtraction operation 2. Compound Operation 3. With true fractional operation"); Op=Sc.nextint (); if(0 = = op) { Break;} if(1 = =op) {System.out.println ("(5 points/way) Please enter the number of questions:"); intn=Sc.nextint (); System.out.print ("Please enter the range of arithmetic (from small to Large):"); intmin=Sc.nextint (); intmax=Sc.nextint (); if(min>max) {System.out.print ("Input Error"); Break; } Random R=NewRandom (); for(i=0;i<n;i++) {a=r.nextint (max)% (max-min+1) +min; b=r.nextint (max)% (max-min+1) +min; intL= R.nextint (s.length);//random number, less than the length of the array, 0~3System.out.print (A+S[L]+B);//Print Random charactersSystem.out.print ("="); DoubleA=sc.nextdouble (); if("+"==S[l]) { if(a==a+b) {System.out.println ("This is right!"); Count1++; } Else{System.out.println ("This is wroing!" + "The correct answer is:" + (A +b)); Count2++; } } Else if("-"==S[l]) { if(A-B) >-11){ if(a==a-b) {System.out.println ("This is right!"); Count1++; } Else{System.out.println ("This is wroing!" + "The correct answer is:" + (A-b)); Count2++; } } Else{a=r.nextint (max)% (max-min+1) +min; b=r.nextint (max)% (max-min+1) +min; if(a==a-b) {System.out.println ("This is right!"); Count1++; } Else{System.out.println ("This is wroing!" + "The correct answer is:" + (A-b)); Count2++; } } } Else if("*"==S[l]) { if(a==a*b) {System.out.println ("This is right!"); Count1++; } Else{System.out.println ("This is wroing!" + "The correct answer is:" + (A *b)); Count2++; } } Else if("/"==S[l]) { if(a==a/b) {System.out.println ("This is right!"); Count1++; } Else{System.out.println ("This is wroing!" + "The correct answer is:" +string.format ("%.2f", A/b)); Count2++; }}} System.out.println ("The question is:" +count1+ "" + "Wrong:" +count2+ "" + "to be divided into:" +5*count1); } Else if(2 = =op) {} Else if(3 = =op) { //molecule intq,p; //Denominator inty,w; System.out.println ("(5 points/way) Please enter the number of questions:"); intn=Sc.nextint (); System.out.print ("Please enter the range of arithmetic (from small to Large):"); intmin=Sc.nextint (); intmax=Sc.nextint (); if(min>max) {System.out.print ("Input Error"); Break; } Random R=NewRandom (); for(i=0;i<n;i++) {Q=r.nextint (max)% (max-min+1) +min; P=r.nextint (max)% (max-min+1) +min; Y=r.nextint (max)% (max-min+1) +min; W=r.nextint (max)% (max-min+1) +min; intL= R.nextint (s.length);//random number, less than the length of the array, 0~3 if((q<y && y!=0) | | (P<w && w!=0) {System.out.println (q+ "/" +y+s[l]+p+ "/" +w);//Print Random charactersSystem.out.print ("="); DoubleA=sc.nextdouble (); } } } Else{System.out.println ("Input error, please re-enter;"); } } }}
View Code
At first, see the topic began to do, no detailed planning, consider their own ideas, think clearly need to define a few classes to achieve the function, the results of all my code is in the main function inside, resulting in my later I wrote the more chaotic, wrong, so seriously formed a bad habit. So I decided to slow down my steps, not blindly pursue to run the results. I want to learn how to use the class to write my program, look at the teacher guidance, thank you!
Arithmetic Upgrade 2