[Experimental requirements]
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.
1. Design Ideas
Random randomly generates 10 numbers, assigns them to the array, and then adds the numbers in the arrays, using the Joptionpane.showmessagedialog message box to output.
2. Program Flowchart
3. SOURCE program code
1 Importjavax.swing.*;2 3 Public classArray {4 5 6 Public Static voidMain (string[] args) {7 8 //TODO auto-generated Method Stub9 TenString output = ""; One A intn[]=New int[10]; - - for(inti=0;i<10;i++) the { -N[i]= (int) (Math.random () *100 ); - } - + - + intA=0; A atOutput + = "Array is: \ n"; - - for(inti=0;i<n.length;i++) - -Output + = N[i] + "\ n"; - inOutput + = "Array and as:"; - to for(inti=0;i<n.length;i++) + -A + =N[i]; the *Output + =A; $ Panax NotoginsengJTextArea Outputarea =NewJTextArea (11, 10 ); - the outputarea.settext (output); + AJoptionpane.showmessagedialog (NULL, Outputarea, "Initializing an Array with a Declaration", joptionpane.information_message);//appears as a dialog box the +System.exit (0 ); - $}
4. Results
5. Programming Summary
int n[]=new int[10];[ Open a new array]
Math.random () [Generate random number]
Joptionpane.showmessagedialog () [Output of message boxes for messages]
Program | Java randomly generates 10 numbers, fills an array and computes the array's and