Java Practice
Class exercises the topic, randomly input a simple arithmetic, the symbol also randomly, does not output the result.
Code:
1 Public Static voidMain (string[] args) {2 //TODO auto-generated Method Stub3string[] Number = {"0", "1", "2", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21 "," 22 "," 23 "," 24 "," 25 "," 26 "," 27 "," 28 "," 29 "};4String[] Fuhao = {"+", "-", "*", "/"};5 6 intOnelength =number.length;7 intTwolength =fuhao.length;8 intThreelength =number.length;9 Ten intRand1 = (int) (Math.random () *onelength); One intRand2 = (int) (Math.random () *twolength); A intRand3 = (int) (Math.random () *threelength); - -String phrase = Number[rand1] + "" +fuhao[rand2] + "" +Number[rand3]; the -System.out.println ("Arithmetic test for" + phrase + "="); -}
The numbers are entered manually, so the code is improved:
1 Public Static voidMain (string[] args) {2 //TODO auto-generated Method Stub3String[] Fuhao = {"+", "-", "*", "/"};4 5 intTwolength =fuhao.length;6 7 intRand1 = (int) (Math.random () * 99);8 intRand2 = (int) (Math.random () *twolength);9 intRand3 = (int) (Math.random () * 99);Ten OneString phrase = Rand1 + "" +fuhao[rand2] + "" +Rand3; A -System.out.println ("Arithmetic test for" + phrase + "="); -}
Summary: Too few Java programming practices
Random input for simple arithmetic