标签:
import javax.swing.*;
public class ShowArrays
{
public static void main(String[] args)
{
int Array[] = new int[10];
for(int i = 0;i < 10;i++)
{
int random = (int) (Math.random() * 100);//产生一个1到100的随机整数
Array[i] = random;
}
int sum = 0;
for(int i = 0;i < 10;i++)
sum = sum + Array[i];//数组求和
String output = new String("数组元素为 "+Array[0]+" "+Array[1]+" "+Array[2]+" "
+Array[3]+" "+Array[4]+"\n"+Array[5]+" "+Array[6]+" "
+Array[7]+" "+Array[8]+" "+Array[9]+"\n"+"数组元素之和为\t"+sum);
JOptionPane.showMessageDialog(null,output,"随机生成数组",JOptionPane.INFORMATION_MESSAGE);
}
}
标签:
原文地址:http://www.cnblogs.com/nxxam/p/4931916.html