标签:
设计思路:
申请随机数100以内的随机数,申请一个数组空间,将随机数存入数组,并计算求和,最后消息框输出结果
流程图:
源代码:
import javax.swing.JOptionPane;
import java.util.Random;
public class SuijiTest {
public static void main(String args[])
{
int sum = 0;
Random random = new Random();
int[] array = new int[10];
for(int i = 0; i < 10; i++)
{
array[i] = random.nextInt(100);
sum +=array[i];
}
JOptionPane.showMessageDialog(null,"十个随机数为:"+array[0]+" "+array[1]+" "+array[2]+" "+array[3]+" "
+array[4]+" "+array[5]+" "+array[6]+" "+array[7]+" "+array[8]+" "+array[9]+" ");
JOptionPane.showMessageDialog(null,"数组元素的和是:"+sum);
}
}
结果截图:
标签:
原文地址:http://www.cnblogs.com/longmakk/p/4931184.html