zoukankan      html  css  js  c++  java
  • 第七周课堂作业

    设计思路:(1)定义10个随机数(用random;

              (2)用for循环让10个随机数相加;

              (3)输出随机数的和。

    程序流程图:

    源代码:

    import java.util.Random;

    import javax.swing.JOptionPane;


    public class A1 {
      public static void main(String[] args)
      {
       int s=0;
       int a[]=new int [10];
      for(int k=0;k<a.length;k++)
      {
       Random Random=new Random();
       Random random1= new Random();
       a[k]=random1.nextInt(10);
      }
     
      for(int i=0;i<a.length;i++)
      {
      
       s=s+a[i];
      }
      String x=new String();
      for(int y=0;y<a.length;y++)
      {
      x=x+" "+a[y];
      }
      x=x+" 和为"+s;
      JOptionPane.showMessageDialog( null,x,
        "Demonstrating String Class Constructors",
        JOptionPane.INFORMATION_MESSAGE );
      
      }

    }

    程序截图:

  • 相关阅读:
    do-while语句
    指针操作符
    字符译码
    PHP流程控制分支结构
    PHP数据类型和常量
    PHP中使用的变量
    第一个PHP程序
    HTML的区块属性
    HTML的定位属性
    HTML的盒子模型
  • 原文地址:https://www.cnblogs.com/ygl888/p/4931712.html
Copyright © 2011-2022 走看看