集册 Java实例教程 数组元素的默认初始化

数组元素的默认初始化

欢马劈雪     最近更新时间:2020-01-02 10:19:05

523
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
数组元素的默认初始化

public class Main {

  private boolean[] myArray = new boolean[3]; // An instance variable


  public Main() {/*来自 n o w  j a v a  . c o m*/

    for (int i = 0; i < myArray.length; i++) {

      System.out.println("bArray[" + i + "]:" + myArray[i]);

    }

  }


  public static void main(String[] args) {

    System.out.println("int array initialization:");

    int[] empId = new int[3]; // A local array variable

    for (int i = 0; i < empId.length; i++) {

      System.out.println("empId[" + i + "]:" + empId[i]);

    }

    System.out.println("boolean array initialization:");

    new Main();

    System.out.println("Reference type array initialization:");

    String[] name = new String[3];

    
展开阅读全文