Check if all prefixes of a number is divisible by remaining count of digits | Java program for the above approach ; Function to check if all prefixes of a number is divisible by remaining count of digits or not ; Traverse and check divisibility for each updated number ; Update the original number ; Driver Code ; Given Input ; Function Call
import java . io . * ; class GFG { public static boolean prefixDivisble ( int n ) { int i = 1 ; while ( n > 0 ) { if ( n % i != 0 ) return false ; n = n / 10 ; i ++ ; } return true ; } public static void main ( String [ ] args ) { int n = 52248 ; if ( prefixDivisble ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }