Centered cube number | Java Program to find nth Centered cube number ; Function to find Centered cube number ; Formula to calculate nth Centered cube number & return it into main function . ; Driver code
import java . io . * ; class GFG { static int centered_cube ( int n ) { return ( 2 * n + 1 ) * ( n * n + n + 1 ) ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . print ( n + " th ▁ Centered " + " ▁ cube ▁ number : ▁ " ) ; System . out . println ( centered_cube ( n ) ) ; n = 10 ; System . out . print ( n + " th ▁ Centered " + " ▁ cube ▁ number : ▁ " ) ; System . out . println ( centered_cube ( n ) ) ; } }