ImportJava.util.*; Public classArithmetictopic {Private StaticRandom random =NewRandom (); PublicArithmetictopic () {//TODO auto-generated Constructor stub } PrivateString Createnumber () {intNumber1 =1+random.nextint (100); intPoint1 = 0; String numberstring=""; if(Random.nextboolean ()) {point1=Number1; Number1= 1+Random.nextint (POINT1); if(Point1==number1) point1=0; } if(point1>0) {numberstring= "" +number1+ "/" +point1; }Else{numberstring= "" +Number1; } returnnumberstring; } PrivateString topicstring () {Charoperator = ' + '; Switch(Random.nextint (3)) { Case0:operator = ' + '; Break; Case1:operator = '-'; Break; Case2:operator = ' * '; Break; Case3:operator = '/'; Break; default: Break; }; returnCreatenumber () +operator+createnumber () + "="; } Public Static voidMain (string[] args) {arithmetictopic topic=NewArithmetictopic (); for(inti=0;i<10;i++) System.out.println (topic.topicstring ()); }}
Program Ideas:
Generate a true score: first produces a 1-100 random integer y, according to the random Boolean value to determine whether to produce a 1-y random integer x as a molecule, to form x/y, if the x/y=1 is directly output x.
Generates arithmetic expression: number x1,x2, inserts a random operator in the middle of the string, and ends with an equal sign output to the command line.
Method of construction 1: Write a program that generates arithmetic topics