I need to write a Java program that does the following - For each of the first ten positive integers, raise them all to power 1, then find that sum. Then raise them all to power 2, and find the sum. Then raise them to power 3, and then find the sum and so on and so forth and then just print out the sums. Basically,
11 + 21 + 31 + ... + 101 = sum1
12 + 22 + 32 + ... + 102 = sum2
13 + 23 + 33 + ... + 103 = sum3
14 + 24 + 34 + ... + 104 = sum4
15 + 25 + 35 + ... + 105 = sum5
and just print out the values of sum1 to sum5.
Here's what I've tried;
public static void main(String[] args) {
for (double power=1;power<=5;power++)
{
for (double n=1;n<=10;n++)
{
double result = (Math.pow(n, power));
if (n%10==0)
{
double sum=0;
sum+=result;
System.out.println(sum);
}
}
}
}
}
I do get five outputs, but not quite the desirable ones. It just prints out
10.0
100.0
1000.0
10000.0
100000.0
How do I fix this?