Check whether sum of digits at odd places of a number is divisible by K | Java implementation of the above approach ; Converting integer to string ; Traversing the string ; Driver code
import java . io . * ; class GFG { static boolean sumDivisible ( int n , int k ) { int sum = 0 ; String num = Integer . toString ( n ) ; int i ; for ( i = 0 ; i < num . length ( ) ; i ++ ) { if ( i % 2 != 0 ) { sum = sum + ( num . charAt ( i ) - '0' ) ; } } if ( sum % k == 0 ) { return true ; } else { return false ; } } public static void main ( String [ ] args ) { int n = 592452 ; int k = 3 ; if ( sumDivisible ( n , k ) ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } }