← All resources

WAP to input a number n and print the sum of the following series: 1 + 8 + 27 + 64 + 125

public class Sum_cb
{
    public static void main(int n)
    {
        int i, s=0;
        for(i=1;i<=n;i++)
        {
            s = s+i*i*i;
        }
        System.out.println("Sum= "+s);
    }
}