Program to check if N is a Hexagonal Number or not | Java program to check if N is a hexagonal number ; Function to check if number is hexagonal ; Calculate the value for n ; Check if n - floor ( n ) is equal to 0 ; Driver code
import java . util . * ; class GFG { static boolean isHexagonal ( int N ) { float val = 8 * N + 1 ; float x = 1 + ( float ) Math . sqrt ( val ) ; float n = ( x ) / 4 ; if ( ( n - ( int ) n ) == 0 ) return true ; else return false ; } public static void main ( String [ ] args ) { int N = 14 ; if ( isHexagonal ( N ) == true ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }