Check if a number is Full Prime | Java program for checking of full prime ; function to check digits ; check all digits are prime or not ; check if digits are prime or not ; To check if n is prime or not ; check for all factors ; To check if n is Full Prime ; The order is important here for efficiency ; driver code
import java . util . * ; class Prime { public static boolean checkDigits ( int n ) { while ( n > 0 ) { int dig = n % 10 ; if ( dig != 2 && dig != 3 && dig != 5 && dig != 7 ) return false ; n /= 10 ; } return true ; } public static boolean prime ( int n ) { if ( n == 1 ) return false ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } public static boolean isFullPrime ( int n ) { return ( checkDigits ( n ) && prime ( n ) ) ; } public static void main ( String [ ] args ) { int n = 53 ; if ( isFullPrime ( n ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }