zoukankan      html  css  js  c++  java
  • 数组

       数组

      为什么要使用数组?

        如果声明的变量较多且同为一种类型的话,那么声明的变量就会显得冗余累赘,

        就可以声明数组避免这个情况出现。

         数组的定义

        在内存空间中开辟出一连串的空间,且长度不变,数据类型必须一致

         数组有那些内容组成

           数组名,长度,下表,数据类型

       数组的声明的三种方式

        1:int [] num =new int[6];

           2:  int []  num = new int [] {12,34,67};

        3:   int []   num  ={12,34,67};

         案例:

               public class shuZu3 {
                     public static void main(String[] args) {
              Scanner input= new Scanner(System.in);
                  int he = 0; 
                 int [] renShu; 
                renShu = new int [9];
                   for(int i =0;i<renShu.length;i++){
                         System.out.print("请输入第" + (i+1) + "个同学音乐课的成绩:");
                         renShu[i]=input.nextInt();
                         he+=renShu[i];
                }
                        System.out.println("一共几个人:"+renShu.length);//告诉它数组的长度
                        System.out.println("五位同学的平均分"+he/renShu.length);
              }
          }

  • 相关阅读:
    跨浏览器的事件处理程序(javascript高级程序设计第二版第十二章)
    json
    html5 本地存储Web Storage
    sicily 6497. 字符统计
    sicily 6415. linear correlation
    sicily 1154. Easy sort
    sicily 6496. 二维数组
    sicily 6423. 反向输出数字
    sicily 1636. show me the money
    sicily 1324. Score
  • 原文地址:https://www.cnblogs.com/li-ding-yong/p/12813783.html
Copyright © 2011-2022 走看看