看板 java 關於我們 聯絡資訊
int[]points={points0,points1,points2,points3,points4,points5}; for( int i =0 ; i<= 4;i++){ userpoints(數字不固定) += points[i]; Log.d(TAG, "點數: " + userpoints); points陣列分別是 10 20 30 40 50 60 出來的點數陣列是 110 130 160 200 250 要怎麼取得陣列最後一個250 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 163.25.119.27 ※ 文章網址: https://www.ptt.cc/bbs/java/M.1478528623.A.77A.html
pttworld: 點數陣列值已確立,看是用什麼儲存。需要過編譯程式碼。 11/07 22:31
h84517: 請問用什麼儲存是什麼意思~存在陣列裡 11/07 23:24
pttworld: 該陣列物件名,請給出可編譯過的程式碼。 11/07 23:26
h84517: 可是userpoints不是一個陣列,只是數值,用來累加陣列 11/07 23:33
pttworld: 請問儲存出來的點數陣列物件名,請給出可編譯過程式碼。 11/07 23:35
a23633302: i<=points.length-1 11/07 23:59
pttworld: 需要points運算,值才會變化。取length-1可以O(1)。 11/08 00:22
steven11329: 晚點回你 11/08 07:59
steven11329: 解說詳見網址http://ideone.com./fOL2Nd 11/08 08:46
pttworld: 幫寫算出陣列最後一個是250的程式。 11/08 09:37
h84517: 非常謝謝各位的詳細解說~~我有照著寫了,晚點看看可不可 11/08 09:51
h84517: 以跑~(。・ω・。) 11/08 09:51
h84517: 謝謝Steven~可是你下面stdout還是一整個陣列 不是只有250 11/08 10:19
steven11329: 只要最後一個就把print放到for外的下面即可。 11/08 10:26
h84517: 成功了 謝謝大家(^ ▽^ ) 11/08 23:34