Javappt after-school assignment letter 1403-2 Huaiyuan 20142897 November 2

Source: Internet
Author: User

Experimental topics:

Randomly generates 10 numbers, fills an array, then displays the array contents with a message box, computes the array element's and displays the result in a message box. Design ideas: First define an array, the capacity is 10, define a string variable to do output backup, in a for loop using random function to generate random numbers, and input into the array, the number of cycles to the length of the group, and Sum, In another for loop, the random number of each loop is initialized in string form to the previously defined variable, with a space interval for each number. Finally, the program flowchart is output as a message box: source code:
ImportJavax.swing.JOptionPane;//introduction of the tools used Public classCount {//Create a public class     Public Static voidMain (string[] args) {//Java Function Entry method        inti = 0;//defining the shaping of variable initialization        intp = 0;//defining the shaping of variable initialization        intC[] =New int[10];//defines an integer array with a capacity of tenString s= "";//Defining string Variables         for(i=0;i<10;i++)        {            intA = (int) (Math.random () *10+1);//Generate random numbersC[i] = A;//inputting random numbers into arraysp = p+c[i];//each cool as a random number, add it to the next sum        }         for(i=0;i<10;i++) {s+ = c[i]+ "";//Enter the random number of each generation into a string variable} joptionpane.showmessagedialog (NULL,                The contents of the array are: "+s+" \ n "+" Output and is: "+p);//Output    }}

Results: Programming Summary: This job is still relatively simple, spend time is not long easy to understand

Javappt after-school assignment letter 1403-2 Huaiyuan 20142897 November 2

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.