fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12.  
  13. List<Long> lista = new ArrayList();
  14.  
  15. long k = 0;
  16. int base = 2;
  17.  
  18. for (long a = 1; a <= 10; a++) {
  19.  
  20. k += (base*a);
  21. lista.add(k);
  22. }
  23.  
  24. System.out.println("Soma="+lista);
  25.  
  26. //base 3
  27.  
  28. System.out.println();
  29.  
  30. lista = new ArrayList();
  31.  
  32. k = 0;
  33. base = 3;
  34.  
  35. for (long a = 1; a <= 10; a++) {
  36.  
  37. k += (base*a);
  38. lista.add(k);
  39. }
  40.  
  41. System.out.println("Soma="+lista);
  42. }
  43. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
Soma=[2, 6, 12, 20, 30, 42, 56, 72, 90, 110]

Soma=[3, 9, 18, 30, 45, 63, 84, 108, 135, 165]