Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
29 lines (26 loc) · 869 Bytes

File metadata and controls

29 lines (26 loc) · 869 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package chap01;
/*
* 简化格式: 数据类型 数组名称 = {值, 值,…}
* 完整格式: 数据类型 数组名称 = new 数据类型[] {值, 值,…}
* */
public class ArrayTest {
public static void main(String args[]) {
int data[] = new int[3]; /*开辟了一个长度为3的数组*/
data[0] = 10; // 第一个元素
data[1] = 20; // 第二个元素
data[2] = 30; // 第三个元素
for(int x = 0; x < data.length; x++) {
System.out.println(data[x]); //通过循环控制索引
}
int temp[] = data;
temp = data; //int temp[] = data;
temp[0] = 99;
for(int i = 0; i < temp.length; i++) {
System.out.println(data[i]);
}
// 二维数组
int[][] data1 = new int[][]{{1, 2, 4},{545, 11},{32, 13131, 4444}};
System.out.println(data1.length);
System.out.println(data1[1].length);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.