Check if a number is a power of another number | Java program to check given number y is power of x ; logarithm function to calculate value ; Note : this is double ; compare to the result1 or result2 both are equal ; Driver Code
class GFG { static boolean isPower ( int x , int y ) { int res1 = ( int ) Math . log ( y ) / ( int ) Math . log ( x ) ; double res2 = Math . log ( y ) / Math . log ( x ) ; return ( res1 == res2 ) ; } public static void main ( String args [ ] ) { if ( isPower ( 27 , 729 ) ) System . out . println ( "1" ) ; else System . out . println ( "0" ) ; } }