Unprimeable Numbers | Java program to check if n is unprimeable Number ; Function to check if N is prime ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to check if n is a unprimeable Number ; Number should be composite ; Converting N to String ; Loop to change digit at every character one by one . ; Loop to store every digit one by one at index j ; Driver code ; Function Call
class GFG { static boolean isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } static boolean isUnPrimeableNum ( int N ) { if ( isPrime ( N ) ) return false ; String s = String . valueOf ( N ) ; for ( int j = 0 ; j < s . length ( ) ; j ++ ) { char [ ] str = s . toCharArray ( ) ; for ( int i = 0 ; i <= 9 ; i ++ ) { char c = ( char ) ( '0' + i ) ; str [ j ] = c ; int Num = Integer . valueOf ( new String ( str ) ) ; if ( str [ j ] != s . charAt ( j ) && isPrime ( Num ) ) { return false ; } } } return true ; } public static void main ( String [ ] args ) { int n = 200 ; if ( isUnPrimeableNum ( n ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }