zoukankan      html  css  js  c++  java
  • 课后作业

    源代码:

    package test6;
    import javax.swing.*;
    
    public class Shuzu {
        public static void main( String args[] )
        {
        String output = "";
        int num=0;
    
        int n[] = new int[10];
        for(int i=0;i<n.length;i++){
        n[i]=(int)(Math.random()*100+1);
        }
    
        output += "Subscript	Value
    ";
    
        for ( int i = 0; i < n.length; i++ ){ 
        output += i + "	" + n[ i ] + "
    ";
        num+=n[i];
        }
    
        JTextArea outputArea = new JTextArea( 11, 10 );
        outputArea.setText( output );
    
        JOptionPane.showMessageDialog( null, outputArea,
        "Initializing an Array with a Declaration",
        JOptionPane.INFORMATION_MESSAGE );
        JOptionPane.showMessageDialog(null,num,"数组中所有元素的和:",
        JOptionPane.INFORMATION_MESSAGE);
    
        System.exit( 0 );
        }
        }

    运行结果:

    设计思路:

    1.使用random随机产生10个数,存入数组中

    2.使用for循环把结果存入一个String对象中

    3.使用for循环求出数组中所有元素的和

    4.使用JTextArea和JOptionPane输出数组的内容

    程序流程图:

  • 相关阅读:
    在线漏洞检测网站
    渗透测试工具库
    端口利用解析
    Linux安全脚本
    Linux常见系统故障
    Oracle
    Redis和MongoDB区别
    MHA在监控和故障转移时都做了什么
    Oracle 11g Dataguard参数详解
    Oracle
  • 原文地址:https://www.cnblogs.com/zyldbk/p/4927373.html
Copyright © 2011-2022 走看看