zoukankan      html  css  js  c++  java
  • 随机数

    设计思路:生成随机数并将随机数分配到 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 );

                        

                 

           }

    }

    结果截图:

  • 相关阅读:
    bfs输出路径 && 最短路(迪杰斯特拉)输出路径
    在Ubuntu虚拟机上搭建青岛OJ
    Delphi System.Fillchar 函数
    Delphi 类Class成员介绍 Private、protected、Public、Published
    通过带Flask的REST API在Python中部署PyTorch
    使用ONNX将模型转移至Caffe2和移动端
    AI框架类FAQ
    Paddle Release Note
    如何在框架外部自定义C++ OP
    如何写新的Python OP
  • 原文地址:https://www.cnblogs.com/wanghao369/p/4928520.html
Copyright © 2011-2022 走看看