Check whether product of digits at even places is divisible by sum of digits at odd place of a number | Java implementation of the above approach ; Below function checks whether product of digits at even places is divisible by sum of digits at odd places ; Converting integer to string ; Traveersing the string ; Driver code
import java . io . * ; class GFG { static boolean productSumDivisible ( int n ) { int sum = 0 ; int product = 1 ; String num = String . valueOf ( n ) ; for ( int i = 0 ; i < num . length ( ) ; i ++ ) { if ( i % 2 != 0 ) { product = product * Character . getNumericValue ( num . charAt ( i ) ) ; } else { sum = sum + Character . getNumericValue ( num . charAt ( i ) ) ; } } if ( product % sum == 0 ) { return true ; } else { return false ; } } public static void main ( String [ ] args ) { int n = 1234 ; if ( productSumDivisible ( n ) ) { System . out . println ( " TRUE " ) ; } else { System . out . println ( " FALSE " ) ; } } }