Java陣列 陣列的基本用法

2021-08-21 03:27:11 字數 1763 閱讀 2650

以二維陣列為例,一位陣列類似

/**

* 二維陣列的基本用法

* @author administrator

* */

public class test01 ,,};

//只宣告第一維長度 ---> 合法

//只宣告第二維長度 ---> 非法

int b = new int[3];

b[0] = new int[2];

b[1] = new int[4];

b[2] = new int[3];

b[0][0]=1;

b[0][1]=2;

b[1][0]=3;

b[1][1]=4;

b[1][2]=0;

b[1][3]=9;

b[2][0]=5;

b[2][1]=6;

b[2][2]=7;

// a[0] b[0]為物件,雖然內容相同但位址不同,返回flase;而具體到ab層次,是具體到某乙個數值,相同返回true

system.out.println(a[0][0]==b[0][1]);

system.out.println(a[0]==b[0]);

} }

一些其他的問題

/**

* 列舉的用法

* 列舉的常量列表可以由數字、字母、下劃線及$組成,且不能用數字開頭,與變數命名規則一致

* 確定乙個字元對應的unicode編碼位置

* 二維陣列的一些問題

* @author administrator

* */

public class test02 ;

// for (int i = 0; i < c.length; i++)

double a = ,,};

double b = ,};

//對於乙個二維陣列,a[0]與b[0]仍是物件,裡面存放著後續維度的陣列,b00為false

boolean b00 = (a[0]==b[0]);

system.out.println(b00);

//a[0][0],b[0][0]具體到乙個數,b01為true

boolean b01 = (a[0][0]==b[0][0]);

system.out.println(b01);

a[0]=b[0];

a[1]=b[1];

system.out.println(a==b);

system.out.println(a.length);

system.out.println(a[0][3]);

system.out.println(a[1][3]);

} }enum weekend

二維陣列的簡單應用,矩陣加和並列印

/**

* 計算矩陣的和並列印

* @author administrator

* */

public class matrix

system.out.println();

} }public static int add(int a, int b)

} return c;

} public static void main(string args) , , };

int b = , , };

int c = add(a, b);

print(c);

}}

Java中陣列的基本用法

陣列的定義 1 資料型別 資料名 資料型別 資料名 new 資料型別 例如 int a new int 2 資料型別 資料名 資料型別 資料名 先宣告 例如 int a 資料名 new 資料型別 再建立陣列 a new int 3 型別 陣列名 例如 int a 陣列的初始化 1 靜態初始化是指在定...

Java陣列的用法

陣列 由型別相同的若干元素組成,下標從0開始 陣列的使用 1.宣告陣列 2.分配空間 3.賦值 4.處理資料 分配空間 陣列名 new 陣列型別 長度 e.g.score new double 5 賦值 陣列型別 陣列名 new 陣列型別 e.g.int numbers new int 索引越界 下...

陣列的基本用法

陣列建立 1.const arr 1,2,3 2.const arr new array 等價於 const arr 3.我們可以給它傳乙個引數,作為陣列長度 const arr1 new array 10 陣列遍歷 1 for迴圈 注意 for迴圈的效率最高,能用for迴圈就用for迴圈。cons...