zoukankan      html  css  js  c++  java
  • 数组

    要求将设计思路、程序流程图、源程序代码、结果截图、编程总结等发表到博客园。

    设计思想:定义一个整型的数组,长度为十, Random random=new Random();

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

               array[i]=random.nextInt(10);

               }

    在用以上函数将数组中的十个数,随机数出,在定义一个整型的sum,用来将数组中的十个数相加求和输出, 用JOptionPane.showMessageDialog( null, output,

                      "Demonstrating String Method concat",

                      JOptionPane.INFORMATION_MESSAGE );将数组和数组合用消息框输出。

    流程图:

     

    package demo;

    import java.util.Random;

    import javax.swing.JOptionPane;

    public class ArrayNum {

    public static void main(String[] args) {

    // TODO 自动生成的方法存根

       int sum=0; 

               Random random=new Random();

               int[]array=new int[10];

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

               array[i]=random.nextInt(10);

               }

               String output = null;

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

                output+=" 数组值为:"+array[i];

               }

               JOptionPane.showMessageDialog( null, output,

                      "Demonstrating String Method concat",

                      JOptionPane.INFORMATION_MESSAGE );

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

                sum+=array[i];

               output="数组和为:"+sum;

                  }

               JOptionPane.showMessageDialog( null, output,

                    "Demonstrating String Method concat",

                    JOptionPane.INFORMATION_MESSAGE );

               }

    }

    上述代码可以顺利通过编译,并且输出一个“很奇怪”的结果:

    为什么会这样?学到后面就明白了,此处先不求甚解

    java.lang包在使用的时候无需显示导入,编译时由编译器自动导入。Object类是类层次结构的根,Java中所有的类从根本上都继承自这个类。Object类是Java中唯一没有父类的类。其它所有的类,包括标准容器类,比如数组,都继承了Object类中的方法。

  • 相关阅读:
    黄聪:C#中CefSharp的简单使用
    ArcGIS Pro关闭窗口和退出
    AddOverlay
    ArcGIS Pro固定纸张限定比例尺自动调整纵横打印
    ArcGIS pro增加一个独立表到地图
    ArcGIS Pro How to remove standalone table from contents
    ArcGIS Pro的进度条
    CreatePolygonGraphicElement
    Creating a Group with a List of Elements
    ArcGISPro理解多线程
  • 原文地址:https://www.cnblogs.com/wanggong2014/p/4927641.html
Copyright © 2011-2022 走看看