zoukankan      html  css  js  c++  java
  • 数组的定义格式

    数组的定义格式:
    (1):元素类型 [ ] 数组名 = new 元素类型[元素个数或数组长度];
    示例:int [ ] arr = new int [5];
    (2):元素类型 [ ] 数组名 = new 元素类型[ ]{元素,元素,元素......};
    示例:int [ ] arr = new int[ ]{1,4,6,24,63,2,5};
    int [] arr = {1,4,6,24,63,2,5};
    数组定义的时候没有赋值,则系统会给其附上一个默认的初始值。

    int [] x = new int[3];
    System.out.println(x[3]);
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:3
    数组角标越界异常(3号角标)

    int [] x = new int[3];
    x = null;
    System.out.println(x[3]);
    Exception in thread "main" java.lang.NullPointerException
    at Test.main(Test.java:11)
    空指针异常
    当引用没有任何指向值为null的时候,该引用还在操作实体。

  • 相关阅读:
    Socket通信
    浏览器调用打印机
    python dict操作
    python list操作
    python 模块Example链接
    python random模块
    python configparser模块
    python unittest模块
    python timeit模块
    python datetime模块
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3015610.html
Copyright © 2011-2022 走看看