Android 台灣中文網
標題:
int問題
[打印本頁]
作者:
ArthasL
時間:
2013-10-10 11:19
標題:
int問題
本帖最後由 ArthasL 於 2013-10-11 21:36 編輯
我寫了一個String location[];
然後想程式運算後把數值放進去作之後再運算之用
但是如何把數值放進去呢?
就像是把 123 放進去 location[0]
456 放進去location[1]這樣??
作者:
ploglin
時間:
2013-10-11 09:45
要運算的話應該要用 int
int location[] = new int[]{123, 456};
複製代碼
作者:
ArthasL
時間:
2013-10-11 09:52
本帖最後由 ArthasL 於 2013-10-11 09:59 編輯
哈哈 我現在才知道 int 原來也可以 int [] 這樣 謝謝了
不過要是只設定 int location[]
要如果才能在後來把東西放進去呢?
int location[];
location[0] = 123;
location[1] = 456;
是類似這樣嗎? 好像運行會出問題
作者:
whl
時間:
2013-10-11 18:49
int location[2];
location[0] = 123;
location[1] = 456;
就會正常了。
作者:
ArthasL
時間:
2013-10-11 18:54
打了第一句 int location[2];
剛試了 出了error 2底下出紅線了
作者:
whl
時間:
2013-10-11 20:40
int location[] = new int[2];
這樣才對。
作者:
ArthasL
時間:
2013-10-11 21:12
沒有error
亦成功放資料進去了
謝謝
歡迎光臨 Android 台灣中文網 (https://apk.tw/)
Powered by Discuz! X3.1