Loop to store every digit one by one at index j
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 ; }