Check whether a given number is Polydivisible or Not | Java program to check whether a number is polydivisible or not ; function to check polydivisible number ; digit extraction of input number ; store the digits in an array ; n contains first i digits ; n should be divisible by i ; Driver code
import java . util . * ; import java . io . * ; class GFG { static void check_polydivisible ( int n ) { int N = n ; Vector < Integer > digit = new Vector < Integer > ( ) ; while ( n > 0 ) { digit . add ( new Integer ( n % 10 ) ) ; n /= 10 ; } Collections . reverse ( digit ) ; boolean flag = true ; n = digit . get ( 0 ) ; for ( int i = 1 ; i < digit . size ( ) ; i ++ ) { n = n * 10 + digit . get ( i ) ; if ( n % ( i + 1 ) != 0 ) { flag = false ; break ; } } if ( flag ) System . out . println ( N + " ▁ is ▁ Polydivisible ▁ number . " ) ; else System . out . println ( N + " ▁ is ▁ Not ▁ Polydivisible ▁ number . " ) ; } public static void main ( String [ ] args ) { int n = 345654 ; check_polydivisible ( n ) ; } }