[ 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