zoukankan      html  css  js  c++  java
  • 数组总结之补充

    补充点:

    1.每个数组都有一个 length属性值;length的属性是 public   final    int

    顾名思义:

    1.1.所以数组一旦常见就不能修改

    1.2.常见数组时必须声明其长度

    2.int a[]=new int[3];

    变量a就是一个引用,指向生成的数组对象的首地址

     

    附上练习代码君(有三维数组彩蛋>,<):

    package com.jacob.javase;


    /*
     * 数组的详细探讨2:
     */
    public class ArrayTest12 {
    public static void main(String[] args) {
    Person[] p = new Person[3];
    Person[][] p1 = new Person[2][3];


    int[][] a = new int[2][3];


    // 探讨存储的值
    // System.out.println(a[0] instanceof int[]);
    // System.out.println(a instanceof int[][]);


    // System.out.println(p[1] instanceof Person);
    // p[1] = new Person(12);
    // System.out.println(p instanceof Person[]);


    // System.out.println(p1[0][1] instanceof Person);
    // System.out.println(p1[0] instanceof Person[]);
    // System.out.println(p1 instanceof Person[][] );
    // 三维数组
    int[][][] a1 = new int[2][3][4];


    // System.out.println(a1 instanceof int[][][]);
    //
    // System.out.println(a1[0] instanceof int[][]);
    //
    // System.out.println(a1[0][0] instanceof int[]);


    for (int i = 0; i < a.length; i++) {
    for (int j = 0; j < a[i].length; j++) {
    for (int k = 0; k < a1[i][j].length; k++) {
    a1[i][j][k] = 100;
    }
    }
    }
    // printThreeDimension(a1);
    }


    // 三维数组遍历
    public static void printThreeDimension(int a[][][]) {
    for (int i = 0; i < a.length; i++) {
    for (int j = 0; j < a[i].length; j++) {
    for (int k = 0; k < a[i][j].length; k++) {
    System.out.print(a[i][j][k] + " ");
    }
    System.out.println(" two ");
    }
    System.out.println(" one ");
    }
    }
    }


    class Person {
    int age;


    public Person(int age) {
    this.age = age;
    }
    }

  • 相关阅读:
    写一点应用关于 Lucene.Net,snowball的重新组装(三)
    写一点应用关于 Lucene.Net,snowball的重新组装(二)
    C++ stirng,int 互转(转载)
    特征词选择算法对文本分类准确率的影响(二)
    webGL简单例子(klayge)
    QT 信号和槽
    windows资源管理(内核对象/GDI对象/user对象)
    memcpy memmove区别和实现
    演示软件SpringHome制作
    在浏览器中加载googleEarth插件
  • 原文地址:https://www.cnblogs.com/xieji233/p/6155646.html
Copyright © 2011-2022 走看看