首页 > 解决方案 > 二维数组是用java定义的吗?如果是,那么输出将是什么?

问题描述

 public class Main {

   public static void main(String[] args) {
       int[][] numbers = {{1, 2, 3} , {4, 5, 6, 7}}; //Is it defined?
       int x = numbers[0][3]; // Should the output be 0?
       System.out.println(x);
   }
}

标签: javaarrays

解决方案


您可以在这里查看官方的 oracle 规范: https ://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html

当您查看章节(数组访问)时,您会看到:“所有数组都是 0-origin。长度为 n 的数组可以由整数 0 到 n-1 索引。”


推荐阅读