Check whether a given number is an ugly number or not | Java implementation to check if a number is ugly number ; Function to check the ugly number ; Base Cases ; Condition to check if a number is divide by 2 , 3 , or 5 ; Driver Code
class GFG { static int isUgly ( int n ) { if ( n == 1 ) return 1 ; if ( n <= 0 ) return 0 ; if ( n % 2 == 0 ) { return ( isUgly ( n / 2 ) ) ; } if ( n % 3 == 0 ) { return ( isUgly ( n / 3 ) ) ; } if ( n % 5 == 0 ) { return ( isUgly ( n / 5 ) ) ; } return 0 ; } public static void main ( String args [ ] ) { int no = isUgly ( 14 ) ; if ( no == 1 ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }