Software Engineering Operations 01

Source: Internet
Author: User

Program requirements: Automatically generate 30 to primary arithmetic questions, support for integers and true fractions

Language used in the program: Java

Design ideas: 1. Generate 3 random number num1,num2,num3. NUM1 and num2 integers with a range of 0-99 num3 to 0-3

Num1,num2 used to calculate, num3 A to Judge +-*/

2. If num3=0 output num1+num2=

If num3=1 output num1+num2=

If num3=2 output num1+num2=

If num3=3 num2==0 re-randomly num2 until not 0, then output num1+num2=

3 true score arithmetic above produces 5 random numbers as a denominator of not 0

4. Call two function loops 30 times in the main function

Program Source code:

 Packagetest; Public classTest {//integer Arithmetic     Public voidTestzheng () {intnum1=0,num2=0,num3=0;//num1,num2 for two 0-99 random integers num3 to 0-3 random integers//Generate random numbersNum1= (int) (Math.random () *100); Num2=(int) (Math.random () *100); NUM3=(int) (Math.random ()); if(num3==0) System.out.println (NUM1+ "+" +num2+ "=");//for + operations        if(num3==1) System.out.println (NUM1+ "-" +num2+ "=");//is-operation        if(num3==2) System.out.println (NUM1+ "*" +num2+ "=");//for * Arithmetic        if(num3==3)        {            if(num2==0)             {                 while(num2==0)//num2 is 0 cannot be the denominatorNum2= (int) (Math.random () *100); }            ElseSystem.out.println (Num1+ "/" +num2+ "=");//for/Operations        }    }    //score Arithmetic     Public voidTestfen () {intNUM1,NUM2,NUM3,NUM4,NUM5;//num1,num3 is a molecule, NUM2,NUM4 is the denominator num5 is 0-3 random number//Generate random numbersNum1= (int) (Math.random () *100); Num2=(int) (Math.random () *100) +1; NUM3=(int) (Math.random () *100); NUM4=(int) (Math.random () *100) +1; NUM5=(int) (Math.random ()); if(num5==0)//for + operationsSystem.out.println (num1+ "/" +num2+ "+" +num3+ "/" +num4+ "="); if(num5==1)//is-operationSystem.out.println (num1+ "/" +num2+ "-" +num3+ "/" +num4+ "="); if(num5==2)//for * ArithmeticSystem.out.println ("(" +num1+ "/" +num2+ ")" + "*" + "(" +num3+ "/" +num4+ ")" + "="); if(num5==3)//for/Operations        {            if(num3==0)//num3 as the denominator is not 0            {                 while(num3==0) num3= (int) (Math.random () *100); }            ElseSystem.out.println ("(" +num1+ "/" +num2+ ")" + "/" + "(" +num3+ "/" +num4+ ")" + "="); }                }     Public Static voidMain (string[] args) {Test T1=NewTest ();  for(inti=0;i<30;i++) {T1.testzheng ();        T1.testfen (); }                        }

Run results (partial):

As for the analysis of the class did not complete the reason: A winter vacation did not practice, feeling unfamiliar.

Software Engineering Operations 01

Related Article

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.