Centered Octagonal Number | Java Program to find nth centered octagonal number ; Function to find centered octagonal number ; Formula to calculate nth centered octagonal number and return it into main function ; Driver Code
import java . io . * ; class GFG { static int centeredoctagonalNumber ( int n ) { return 4 * n * ( n - 1 ) + 1 ; } public static void main ( String args [ ] ) { int n = 6 ; System . out . print ( n + " th ▁ centered ▁ " + " octagonal ▁ number : ▁ " ) ; System . out . println ( centeredoctagonalNumber ( n ) ) ; n = 11 ; System . out . print ( n + " th ▁ centered ▁ " + " octagonal ▁ number : ▁ " ) ; System . out . println ( centeredoctagonalNumber ( n ) ) ; } }