Average of Cubes of first N natural numbers | Java program for the above approach ; Function to find average of cubes ; Storing sum of cubes of numbers in sum ; Calculate sum of cubes ; Return average ; Driver Code ; Given Number ; Function Call
import java . util . * ; import java . io . * ; class GFG { static double findAverageOfCube ( int n ) { double sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { sum += i * i * i ; } return sum / n ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . print ( findAverageOfCube ( n ) ) ; } }