随机数
随机数
源代码
package random;
import javax.swing.*;
public class Sum
{
public static void main(String []args)
{
String output= "10个1000以内的随机数为:\n";
int sum=0;
int a []=new int [10];//初始化
for(int i = 0;i<10;i++)//for循环
{
a[i]=(int) (Math.random()*1000);
output += " "+a[i];
sum += a[i];
}
output +="\n\n十个数的和是:"+sum;
JOptionPane.showMessageDialog(null,output,"结果",
JOptionPane.PLAIN_MESSAGE);
}
}
实验截图
流程图