Annie makes a program to print the product of cubes of the first 10 whole numbers. She writes the
following program
integer x = 0 // statement 1 integer sum = 0 // statement 2 while ( x < 10 ) // statement 3
{
sum = x*x*x // statement 4 x = x + 1 // statement 5
}
print sum // statement 6
Is her program correct? If not, which statement will you modify to correct it?
Answers
Answered by
4
The sum statement is wrong it would not previous sum again and again.
while(x<=10)
{
sum+= (int ) Math.pow(x,3); // sum=sum+x*x*x;
x++;
}
System.out.println("Sum is"+sum);
}
Hope it will help you @
Mark me brainlest @
Similar questions