Function to calculate sum of digits of an integer
static int getSum ( int n ) { int ans = 0 ; char [ ] arr = ( String . valueOf ( n ) ) . toCharArray ( ) ; for ( char ch : arr ) { ans += Character . getNumericValue ( ch ) ; } return ans ; }