Design ideas:
1. Randomly generate 10 numbers using random, which is stored in the array
2. Use a For loop to store the result in a String object
3. Use the For loop to find all the elements in the array and
4. Using JTextArea and Joptionpane to output the contents of an array
Program Flowchart:
SOURCE program code:
Import javax.swing.*;
public class Initarray {
public static void Main (String args[])
{
String output = "";
int num=0;
int n[] = new INT[10];
for (int i=0;i<n.length;i++) {
n[i]= (int) (Math.random () *100+1);
}
Output + = "subscript\tvalue\n";
for (int i = 0; i < n.length; i++) {
Output + = i + "\ t" + n[i] + "\ n";
Num+=n[i];
}
JTextArea Outputarea = new JTextArea (11, 10);
Outputarea.settext (output);
Joptionpane.showmessagedialog (null, Outputarea,
"Initializing an Array with a Declaration",
Joptionpane.information_message);
Joptionpane.showmessagedialog (Null,num, "the and of all elements in the array:",
Joptionpane.information_message);
System.exit (0);
}
}
Program results:
Randomly generate 10 numbers, populate an array, then display the array contents with a message box, then calculate the array elements and display the results in a message box