Random input for simple arithmetic

Source: Internet
Author: User

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

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.