Self Numbers | Java implementation to check if the number is a self number or not ; Function to find the sum of digits of a number N ; Function to check for Self number ; Driver code
class GFG { static int getSum ( int n ) { int sum = 0 ; while ( n != 0 ) { sum = sum + n % 10 ; n = n / 10 ; } return sum ; } static boolean isSelfNum ( int n ) { for ( int m = 1 ; m <= n ; m ++ ) { if ( m + getSum ( m ) == n ) return false ; } return true ; } public static void main ( String [ ] args ) { int n = 20 ; if ( isSelfNum ( n ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }