Find whether a given integer is a power of 3 or not | Java program to check if a number is power of 3 or not . ; Returns true if n is power of 3 , else false ; The maximum power of 3 value that integer can hold is 1162261467 ( 3 ^ 19 ) . ; Driver code
public class Power_3 { static boolean check ( int n ) { if ( n <= 0 ) return false ; return 1162261467 % n == 0 ; } public static void main ( String args [ ] ) { int n = 9 ; if ( check ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }