Java after-class job 5

Source: Internet
Author: User

[ problem ] randomly generates a number of numbers, fills 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:

1. apply for an array of length ten

2. The computer randomly generates a number and assigns it to the array

3. Message box displays array contents

4. Then calculate the array elements and

5. Displaying the elements of an array in a message box

Program Flowchart:

SOURCE program code:

Import Java.util.Random;

Import Javax.swing.JOptionPane;

public class Test {

public static void Main (string[] args)

{

Int[] A;

int sum=0;

A=new INT[10];

String output = null;

output= "Computer-generated 1 to 99 of 10 random numbers are: \ n";

for (int i=0;i<a.length;i++)

{

A[i] = new Random (). Nextint (99) + 1; Randomly generates 1-99 of a number

output+= "a[" + (i+1) + "]=" +a[i]+ "\ n";

}

for (int i=0;i<a.length;i++)

Sum=sum+a[i];

Output+= "The and of these 10 numbers is:" +sum;

Joptionpane.showconfirmdialog (null, Output);

}

}

Results:

Java after-class job 5

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.