产生随机数代码

时间:2022-12-07 16:06:14

package t9;

import java.util.Random;

import javax.swing.JOptionPane;

public class t9 {

public static void main(String[] args) 
{


int []a=new int[10];
int i,k=0;
for(i=0;i<10;i++)
{
Random random1= new Random();
a[i]=random1.nextInt(100);
k=k+a[i];
}
String x=new String();
for(i=0;i<10;i++)
{
x=x+" "+a[i];
}
x=x+"\n和为"+k;
JOptionPane.showMessageDialog( null, x,
"Demonstrating String Class Constructors",
JOptionPane.INFORMATION_MESSAGE );

}

}