Program to check if N is a Octagonal Number | Java program for the above approach ; Function to check if N is a octagonal number ; Condition to check if the number is a octagonal number ; Driver code ; Given Number ; Function call
import java . io . * ; import java . util . * ; class GFG { public static boolean isoctagonal ( int N ) { double n = ( 2 + Math . sqrt ( 12 * N + 4 ) ) / 6 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 8 ; if ( isoctagonal ( N ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }