• 数组中的常见异常: 1. 数组角标越界的异常:ArrayIndexOutOfBoundsExcetion 2. 空指针异常:NullPointerException


    数组中的常见异常:  1. 数组角标越界的异常:ArrayIndexOutOfBoundsExcetion   2. 空指针异常:NullPointerException

    package com.ch.java;
    /*
    * 数组中的常见异常:
    * 1. 数组角标越界的异常:ArrayIndexOutOfBoundsExcetion
    *
    * 2. 空指针异常:NullPointerException
    *
    */
    public class ArrayExceptionTest {
    public static void main(String[] args) {

    //1. 数组角标越界的异常:ArrayIndexOutOfBoundsExcetion
    int[] arr = new int[]{1,2,3,4,5};

    // for(int i = 0;i <= arr.length;i++){
    // System.out.println(arr[i]);
    // }

    // System.out.println(arr[-2]);

    // System.out.println("hello");

    //2.2. 空指针异常:NullPointerException
    //情况一:整个数组的指针是空的
    // int[] arr1 = new int[]{1,2,3};
    // arr1 = null;
    // System.out.println(arr1[0]);

    //情况二:二级数组没有定义
    // int[][] arr2 = new int[4][];
    // System.out.println(arr2[0][0]);

    //情况三:数组的具体元素对象为空
    String[] arr3 = new String[]{"AA","BB","CC"};
    arr3[0] = null;
    System.out.println(arr3[0].toString());
    }
    }

    不积跬步,无以至千里;不积小流,无以成江海。
  • 相关阅读:
    GitLab 介绍
    git 标签
    git 分支
    git 仓库 撤销提交 git reset and 查看本地历史操作 git reflog
    git 仓库 回退功能 git checkout
    python 并发编程 多进程 练习题
    git 命令 查看历史提交 git log
    git 命令 git diff 查看 Git 区域文件的具体改动
    POJ 2608
    POJ 2610
  • 原文地址:https://www.cnblogs.com/CCTVCHCH/p/14541141.html
Copyright © 2020-2023  润新知