首页 > 其他 > 详细

随机数

时间:2015-11-01 21:12:35      阅读:288      评论:0      收藏:0      [点我收藏+]

设计思路:生成随机数并将随机数分配到 char类型的数组中,再将char类型转换为int类型,计算并输出结果。

源程序代码

import java.util.Random;

import javax.swing.*;

public class Array1 {

       public static void main(String Args[])

       {

              int a[]=new int [10];

              int num = 0;

              String output="";

              for(int i=0;i<10;i++)

              {

                     a[i]=(int)(Math.random()*100);

              }

              for(int  element:a)

              {

                     output+=element+" ";

                  num+=element;

              }

                     JOptionPane.showMessageDialog( null,"随机数为"+output ,

                       "Initializing an Array with a Declaration",

                       JOptionPane.INFORMATION_MESSAGE );

                     JOptionPane.showMessageDialog( null,"和为"+num ,

                              "Initializing an Array with a Declaration",

                              JOptionPane.INFORMATION_MESSAGE );

                    

             

       }

}

结果截图:

技术分享技术分享

随机数

原文:http://www.cnblogs.com/wanghao369/p/4928520.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!