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