Check whether a number can be expressed as a product of single digit numbers | Java implementation to check whether a number can be expressed as a product of single digit numbers ; Number of single digit prime numbers ; function to check whether a number can be expressed as a product of single digit numbers ; if ' n ' is a single digit number , then it can be expressed ; define single digit prime numbers array ; repeatedly divide ' n ' by the given prime numbers until all the numbers are used or ' n ' > 1 ; if true , then ' n ' can be expressed ; Driver program to test above
import java . util . * ; class GFG { static int SIZE = 4 ; static boolean productOfSingelDgt ( int n ) { if ( n >= 0 && n <= 9 ) return true ; int [ ] prime = { 2 , 3 , 5 , 7 } ; for ( int i = 0 ; i < SIZE && n > 1 ; i ++ ) while ( n % prime [ i ] == 0 ) n = n / prime [ i ] ; return ( n == 1 ) ; } public static void main ( String [ ] args ) { int n = 24 ; if ( productOfSingelDgt ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }