Program | Java randomly generates 10 numbers, fills an array and computes the array's and

Source: Internet
Author: User

[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

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.