Arithmetic Upgrade 2

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.