java - 二维数组是用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);
}
}
解决方案
您可以在这里查看官方的 oracle 规范: https ://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html
当您查看章节(数组访问)时,您会看到:“所有数组都是 0-origin。长度为 n 的数组可以由整数 0 到 n-1 索引。”
推荐阅读
- css - 未捕获的 DOMException:无法在 'ShadowRoot' 上设置 'adoptedStyleSheets' 属性:无法采用非构造样式表
- python - Python 底图热图
- python - 选择关联表中至少有 30 个 id 实例的所有行
- c++ - 如何打印与我的功能的距离?
- javascript - 选择特定值时将下拉值重置为默认值(选择)
- php - 无法将带有“.ics”的日历事件添加到 Outlook 365
- apache-kafka - 当消费者偏移量在段文件中时,Kafka 如何处理保留期到期的情况?
- firebase - 屏幕之间出现空错误时调用了 getter 'uid'
- mysql - 将 DATE() 与 SELECT 一起使用
- javascript - 我如何重构我的 JS 以使用更少的 if else 语句并减少重复