Software engineering after-work--a randomly generated 30-channel arithmetic written in Java

Source: Internet
Author: User

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

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.