After-school assignments 1

Source: Internet
Author: User

1. Program Design Ideas

1) generate two random numbers first;

2) Place the symbol into a 4-length array, generating random symbols by randomly generating 0-3 random numbers

3) again when the calculation, divided into two, one is a false fractional operation, the other is not fractional operations, which are generated by random;

4) Then use the switch to select the statement to carry out four different operations;

5) When running to division, consider that the denominator cannot be 0.

2 program code

 Packagearithmetic;ImportJava.util.Random; Public classfouroperations { Public Static voidMain (String args[]) {string Firstnumber=NULL, Secondnumber =NULL; Random Random=NewRandom ();  for(inti=0;i<20;i++)        {            intTemp=math.abs (Random.nextint ()%2); if(temp==1) {Firstnumber= "(" +string.valueof (Math.Abs (Random.nextint ()%100) + "/" +string.valueof (Math.Abs (Random.nextint ()%100) + ")"); Secondnumber= "(" +string.valueof (Math.Abs (Random.nextint ()%100) + "/" +string.valueof (Math.Abs (Random.nextint ()%100) + ")"); }            Else            {                intf=Random.nextint (); Firstnumber=string.valueof (Math.Abs (f%100)); ints=Random.nextint (); Secondnumber=string.valueof (Math.Abs (s%100)); }            Charfuhao[]={' + ', '-', ' * ', '/'}; intk=Random.nextint (); intDemp=math.abs (k%4); Switch(Fuhao[demp]) { Case+: {System.out.println (Firstnumber+ "+" +secondnumber+ "="); } Break;  Case‘-‘: {System.out.println (Firstnumber+ "-" +secondnumber+ "="); } Break;  Case‘*‘: {System.out.println (Firstnumber+ "*" +secondnumber+ "="); } Break;  Case‘/‘:             {                 if(secondnumber!= "0") {System.out.println (Firstnumber+ "/" +secondnumber+ "="); }                 }            }        }    }}

3 Running Results
(87/48)-(2/79) =
(43/68) + (48/25) =
96*74=
97*56=
(73/9)/(10/98) =
(54/5)-(29/41) =
(22/51) + (13/70) =
(2/53) * (8/75) =
0-28=
(39/3)-(45/66) =
57/22=
(1/50) * (36/92) =
37*44=
(46/44) * (39/74) =
33+58=
38-27=
65-3=
16+63=
(71/32)/(40/73) =
20*41=

4. The reason why the individual class is not completed is because: I use the Java language, some Java language is not very familiar with, so need to find the code examples previously learned, resulting in the class is not completed on time.

After-school assignments 1

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.