Program:
public static void main(String[] args) {
List<Long> lista = new ArrayList();
long k = 0;
for (long a = 1; a <= 10; a++) {
k = k+2;
lista.add(k);
}
System.out.println("Soma="+lista);
}
}
Itseemstobeallright,butinfactthisisnotan"added sequence".
What the program does is just add the numbers from 2
to 2
. (2 + 2 + 2 + 2 + 2)
So this way from 1
to 10
are [2, 4, 6, 8, 10, 12, 14, 16, 18, 20].
What I'm really looking for is a sum in sequence and does not add from 2
to 2
, or 3
to 3
, or 4
to 4
.
Example: 1+2+3+4+5+6+7+8+9+10
(would be rising) that would be the sequence!
And not a "stop sum" (1 + 1 + 1 + 1 + 1).
Same as 2
= 2+4+6+8+10
Same as 3
= 3+6+9+12
Same as 4
= 4+8+12+16
In my program print: Sum = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
(2 + 2 + 2 + 2 + 2, etc.)
If it were in the "added stream" of 2
.
This would be the result: Sum = [2, 6, 12, 20, 30, 42, 56, 72, 90, 110]
(2 + 4 + 6 + 8 + 10, etc.)
If it were in the "added stream" of 3
.
This would be the result: Sum = [3, 9, 18, 30, 45, 63, 84, 108, 135, 165]
(3 + 6 + 9 + 12 + 15, etc.)