跳到主要内容

Java 数组

使用:

int[] myArray = new int[5];

myArray[0] = 10; // 索引从0开始
myArray[1] = 20;

二维数组:

[
[“张三”, 18, “男”],
[“李四”, 20, “女”],
[“王五”, 19, “男”],
[“赵六”, 17, “女”],
[“赵七”, 22, “男”]
]

或(?):

String[][] students = {
{"张三", "18", "男"},
{"李四", "20", "女"},
{"王五", "19", "男"},
{"赵六", "17", "女"},
{"赵七", "22", "男"}
};
for (int i = 0; i < students.length; i++) {
System.out.println("姓名:" + students[i][0] + ",年龄:" + students[i][1] + ",性别:" + students[i][2]);
}