fork download
  1.  
  2. import java.util.*;
  3. import java.lang.*;
  4. import java.io.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. /* int[] points = {
  11. * points0, points1,
  12. * points2, points3,
  13. * points4, points5
  14. * };
  15. * for(int i=0; i<=4; i++){
  16. * userpoints(數字不固定) += points[i];
  17. * Log.d(TAG, "點數: " + userpoints);
  18. * }
  19. * points陣列分別是 10 20 30 40 50 60
  20. * 出來的點數陣列是 110 130 160 200 250 要怎麼取得陣列最後一個250?
  21. *
  22. * 觀察數列110 130 160 200 250 恰好是初始up為100
  23. * 下一個up = 前一個up + p[i]
  24. */
  25. int p[] = {10, 20, 30, 40, 50, 60};
  26. int up = 100; //<=將up放到for外面就可以保存之後加出來的up
  27. for(int i=0; i<=4; i++){
  28. up += p[i]; //將現在的up + p[i]變成下一個up
  29. System.out.print(up);
  30.  
  31. /*排版用可以不理會*/
  32. if(i != 4){
  33. System.out.print(", ");
  34. }
  35. }
  36. }
  37. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
110, 130, 160, 200, 250