int關鍵字表示32位元的整數,範圍從-2,147,483,648到2,147,483,647存儲值的整數類型。
可以這樣宣告:
1 2 3 4 |
int numberInt = 0; int numberInt = -1; int numberInt = 1000; int numberInt = -999999; |
只要在允許範圍皆可
若要從其他類型數字列如float轉型到int,可以透過以下寫法:
1 2 3 4 |
int floToInt = (int)3.3f; //或者 float number = 3.3f; int floToInt = (int)number; |