Find two numbers whose sum is N and does not contain any digit as K | Java program for the above approach ; Function to find two numbers whose sum is N and do not contain any digit as k ; Check every number i and ( n - i ) ; Check if i and n - i doesn 't  contain k in them print i and n-i ; Check if flag is 0 then print - 1 ; Driver code ; Given N and K ; Function call
import java . util . * ; class GFG { static int freqCount ( String str , char k ) { int count = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) == k ) count ++ ; } return count ; } static void findAandB ( int n , int k ) { int flag = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( freqCount ( Integer . toString ( i ) , ( char ) ( k + 48 ) ) == 0 && freqCount ( Integer . toString ( n - i ) , ( char ) ( k + 48 ) ) == 0 ) { System . out . print ( " ( " + i + " , ▁ " + ( n - i ) + " ) " ) ; flag = 1 ; break ; } } if ( flag == 0 ) System . out . print ( - 1 ) ; } public static void main ( String [ ] args ) { int N = 100 ; int K = 0 ; findAandB ( N , K ) ; } }