Design ideas:
1. Generate random numbers in the array;
2. The final result is calculated by cyclic addition
3. Display results with Joptionpane.showmessagedialog
Flow chart:
SOURCE program code:
Import javax.swing.*;
public class Suijishu {
public static void Main (string[] args) {
TODO auto-generated Method Stub
Int[] arr=new int[10];// definition array
String output= "";
int j=0;
output+= "subscript\tvalue\n";
for (int i=0;i<10;i++)
{
arr[i]= (int) (Math.random () *100);// randomly generate integers in the 0-100 range
output+=i+ "\ t" +arr[i]+ "\ n";
}
JTextArea outputarea=new JTextArea (11,10);
Outputarea.settext (output);
for (int i=0;i<10;i++)
{
J+=arr[i];
}
Joptionpane.showmessagedialog (Null,outputarea, " array element ", joptionpane.information_message);
Joptionpane.showmessagedialog (Null,j, " array elements and ", joptionpane.information_message);
System.exit (0);
}
}
Operation Result:
Add array elements