[toc] https://docs.oracle.com/javase/tutorial/java/nutsandbolts/expressions.html ## Expression 是一個以變數, 運算子, method invocations組成的值. Example: int <font color="00FF00">cadence = 0</font>; <font color="00FF00">anArray[0] = 100</font>; System.out.println(<font color="00FF00">"Element 1 at index 0: " + anArray[0]</font>); int <font color="00FF00">result = 1 + 2</font>; // 這裡有兩個expression ! if (<font color="00FF00">value1 == value2</font>) System.out.println(<font color="00FF00">"value1 == value2"</font>); --- ## Statement 很像是自然語言的一個句子。 一個statement夠成一個完整的執行單元。 這裡隨便指出一些statement, 當然還有很多種: - assignment statement ``` aValue = 8933.234; ``` - increment statement ``` aValue++; ``` - Method invocations statement ``` System.out.println("Hello World!"); ``` - object creation statement ``` new Object(); ``` --- ### 分號 (;) 除了以下介紹的Block, 其餘statement都必須要以```;```結尾。 ## Block 是一個內有{0,}個statement的statement ```java { System.out.println("Hello World!"); int i = 0; } ``` --- 區塊內變數不能重複 ```java // 錯誤 { int a; { int a; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up