+ 1
1+8+27..........1000
Code for program in java
7 Respostas
+ 7
Actually that has a cool formula.
Let's start with a simple example:
1^3 + 2^3 = 1 + 8 = 9
We got a square:
9 = 3^2
1^3 + 2^3 + 3^3 = 1 + 8 + 27 = 36
We got another square:
36 = 6^2
And:
1 + 2 = 3
1 + 2 + 3 = 6
Because:
1^3 + 2^3 = (1 + 2)^2,
1^3 + 2^3 + 3^3 = (1 + 2 + 3)^2,
1^3 + 2^3 + 3^3 + 4^3 = (1 + 2 + 3 + 4)^2
and etc. are true, we can conclude that it is true for all:
1^3 + 2^3 + 3^3 + ... + n^3 = (1 + 2 + 3 + ... + n)^2
(1, 2, 3, ... n) is an arithmetic sequence, and arithmetic sequence a has a function, which can be used to calculate the sum of a certain range:
n*(a_1 + a_n)/2
So we can calculate the sum of the sequence:
s = n*(1 + n)/2
And we'll get a formula to calculate those cube sequences:
(n*(1 + n)/2)^2
What is 1^3 + 2^3 + 3^3 + ... + 100^3?
Answer:
(100*(1 + 100)/2)^2
= 25'502'500
I can't prove why:
1^3 + 2^3 + 3^3 + ... + n^3 = (1 + 2 + 3 + ... + n)^2
But if someone can prove it without Google I would appreciate it.
https://www.sololearn.com/post/150295/?ref=app
+ 1
Can you show us your attempt?
+ 1
I too wanted answer
+ 1
I'm asking for your code, so we can help you fix it if there are any mistakes.
+ 1
class seven
{
void main ()
{
int s = 0;
for(int a = 1;a<=10;a++)
{
s=s+a*a*a;
}System.out.println(s);
}}
Plz give me answer
+ 1
Your code is almost correct, but this is not the right way to write programs in Java. Take a look at the beginning of the course please, I'm sure you'll find out the answer.