Gapful Numbers | Java program for the above approach ; Find the first digit ; Find total number of digits - 1 ; Find first digit ; Return first digit ; Find the last digit ; Return the last digit ; A function to check Gapful numbers ; Return true if n is gapful number ; Driver code ; Given number ; Function call
class GFG { static int firstDigit ( int n ) { int digits = ( int ) ( Math . log ( n ) / Math . log ( 10 ) ) ; n = ( int ) ( n / Math . pow ( 10 , digits ) ) ; return n ; } static int lastDigit ( int n ) { return ( n % 10 ) ; } static boolean isGapful ( int n ) { int first_dig = firstDigit ( n ) ; int last_dig = lastDigit ( n ) ; int concatenation = first_dig * 10 + last_dig ; return ( n % concatenation == 0 ) ; } public static void main ( String [ ] args ) { int n = 108 ; if ( isGapful ( n ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }