to the power of java code example

Example 1: how to find power of a number in java

int powerOfNumber = (int) Math.pow(number, power);

Example 2: how to use pow function in java

import java.lang.Math; 
  
class Gfg { 
  
    // driver code 
    public static void main(String args[]) 
    { 
        double a = 30; 
        double b = 2; 
        System.out.println(Math.pow(a, b)); 
  
        a = 3; 
        b = 4; 
        System.out.println(Math.pow(a, b)); 
  
        a = 2; 
        b = 6; 
        System.out.println(Math.pow(a, b)); 
    }

Example 3: raise number to power java

Math.pow(number, power);

Example 4: java is power of 2

boolean result = number > 0 && ((number & (number - 1)) == 0);

Tags:

Java Example