natman
0
Q:

how to do power 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)); 
    } 
11
Math.pow(number, power);
15
// Java program to demonstrate working 
// of java.lang.Math.pow() method 
import java.lang.Math; // importing java.lang package 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        double nan = Double.NaN; 
        double result; 
  
        // Here second argument is NaN, 
        // output will be NaN 
        result = Math.pow(2, nan); 
        System.out.println(result); 
  
        // Here second argument is zero 
        result = Math.pow(1254, 0); 
        System.out.println(result); 
  
        // Here second argument is one 
        result = Math.pow(5, 1); 
        System.out.println(result); 
    } 
} 
0

New to Communities?

Join the community