Java randomly generates A number of numbers, populates an array, and then displays the array contents with a message box , then computes the array elements and displays the results in a message box.
Design ideas: You can use Math.random () *1000 to generate 1000 of the random number, and then into the array, then read the array, output random number, while the addition calculation, and finally all the results in the form of a message box output.
Program Flowchart:
Source:
Packagesum of random numbers;Importjavax.swing.*; Public classSum { Public Static voidMain (String args[]) {string output= "10 x 1000 or less random number: \ n"; intSum=0; intA []=New int[10]; for(inti = 0;i<10;i++) {A[i]=(int) (Math.random () *1000); Output+= " "+A[i]; Sum+=A[i]; } Output+ = "\ n 10 number of and is:" +sum; Joptionpane.showmessagedialog (NULL, output, "result", Joptionpane.plain_message); }}
Results:
Summary: Using Math.random () *n can generate random numbers in any n, and finally utilize Joptionpane.showmessagedialog (null,output, ""joptionpane.plain_ MESSAGE);
you can then output the results in a dialog box.
Java generates 10 random numbers, fills an array, displays the array contents with a message box, and then sums the output