Junction Numbers | Java program for above approach ; Function to find the sum Of digits of N ; To store sum of N and sumOfdigitsof ( N ) ; extracting digit ; Function to check Junction numbers ; To store count of ways n can be represented as i + SOD ( i ) ; Driver Code ; Function Call
class GFG { static int sum ( int n ) { int sum = 0 ; while ( n != 0 ) { int r = n % 10 ; sum = sum + r ; n = n / 10 ; } return sum ; } static boolean isJunction ( int n ) { int count = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( i + sum ( i ) == n ) count ++ ; } return count >= 2 ; } public static void main ( String [ ] args ) { int N = 111 ; if ( isJunction ( N ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }