Presentation is loading. Please wait.

Presentation is loading. Please wait.

JAVA 程式設計與資料結構 第四章 陣列、字串與數學物件.

Similar presentations


Presentation on theme: "JAVA 程式設計與資料結構 第四章 陣列、字串與數學物件."— Presentation transcript:

1 JAVA 程式設計與資料結構 第四章 陣列、字串與數學物件

2 A.length代表陣列的長度,使用A[index]來取得陣列中之值
陣列 (Array) A.length代表陣列的長度,使用A[index]來取得陣列中之值

3 陣列的宣告 int a[]; 或 int [] a; // 陣列長度未定 int a[] = new int[n]; // 陣列長度為n
二維陣列的宣告 Int a[][]; Int a[][] = new int[2][3]; Int a[][] = {{1, 2, 3}, {7, 8, 9}};

4 物件陣列 內含電視物件的陣列

5 字串 (String) 字串的宣告 String s; String s = “ABC”;
String s = null; // String為物件,故可指派null String s = new String() ; String s = new String(char[]) ; String s = new String(char[], 起始值,長度) ; String s = new String(“A String”) ;

6 字串方法(例)-- charAt() & length()
class StringDemo2{ public static void main(String args[]) { String name = "Sumantha"; int size = name.length(); // 取得字串長度 for(int i = 0; i < size; i += 2) { System.out.println(name.charAt(i)); } // for }//main }//StringDemo2

7 StringTokenizer物件 用來分解字串之方法 根據其建構子來宣告,如
 StringTokenizer st = new StringTokenizer(str, “|”);根據字串中的“|”來分解字串 使用st.hasMoreTokens()方法來判斷是否尚有Token 使用st.nextToken(); 方法來取得下一個Token


Download ppt "JAVA 程式設計與資料結構 第四章 陣列、字串與數學物件."

Similar presentations


Ads by Google