1
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);
}
}
It seems to be all right, but actually this is not a "sequence plus".
What the program does is just add up the numbers of 2
in 2
. (2+2+2+2+2)
So that way of 1
to 10
stay [2, 4, 6, 8, 10, 12, 14, 16, 18, 20].
What I really seek is a sum in sequence and not a sum of 2
in 2
, or 3
in 3
, or 4
in 4
.
Example: 1+2+3+4+5+6+7+8+9+10
(would be rising) that would be the sequence!
Not a "stop sum" (1+1+1+1+1+1).
Equal to 2
= 2+4+6+8+10
Equal to 3
= 3+6+9+12
Equal to 4
= 4+8+12+16
In my program print: Soma=[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
(2+2+2+2+2,etc.)
If he were in the "added sequence" of 2
.
That would be the result: Sum=[2, 6, 12, 20, 30, 42, 56, 72, 90, 110]
(2+4+6+8+10, etc.)
If he were in the "added sequence" of 3
.
That would be the result: Sum=[3, 9, 18, 30, 45, 63, 84, 108, 135, 165]
(3+6+9+12+15, etc.)
You can add the code of this program that originated this problem?
– user28595
It would be good to put the code, not a screenshot of it. You have the format tool for this in the toolbar, indicated by the icon
{ }
– Bacco