Array class Assignments

Source: Internet
Author: User

Array class Assignments

First, design ideas

Define an array of length 10, then generate 10 1-10 random numbers, store them in an array, then display them in a dialog box, then define a sum function and output 10 numbers.

Second, the source program code

Package SDDW;

import javax.swing.*;

Public class SWW { public static void main (String args[]) {

int i;

double A;

String output= "";

Double []b=new double [10];

for (i=1;i<b.length;i++)

{

A=math. Random () *10;

B[i]=a;

}

Output + = "subscript\tvalue\n";

for (i = 0; i < b.length; i++)

Output + = i + "\ t" + b[i] + "\ n";

JTextArea Outputarea = new jtextarea (11, 10);

Outputarea.settext (output);

Joptionpane. Showmessagedialog ( null, Outputarea,

"Initializing an Array with a Declaration",

Joptionpane. information_message );

double sum=0;

for (i=0;i<b.length;i++)

{

Sum+=b[i];

}

Joptionpane. Showmessagedialog ( null, SUM,

"Initializing an Array with a Declaration",

Joptionpane. information_message );

}

}

Iii. Results

Array class Assignments

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.