Computer Science, asked by Ayushmaanj, 1 year ago

write a program in Java to print the cubes of first fifteen natural numbers

Answers

Answered by 9257
14
// Simple Java program to find sum of series

// with cubes of first n natural numbers

 

import java.util.*;

import java.lang.*;

class GFG

{

 

    /* Returns the sum of series */

    public static int sumOfSeries(int n)

    {

        int sum = 0;

        for (int x=1; x<=n; x++)

            sum += x*x*x;

        return sum;

    }

 

// Driver Function

    public static void main(String[] args)

    {

        int n = 5;

        System.out.println(sumOfSeries(n));

 

    }

}

 




Similar questions