Java Math exponent operations

Question

We would like to compute exponent operations for the following:

base is 2 and power is 3
base is 4 and power is 0.5
base is 2.5 and power is 2
base is 2.5 and power is -2

Use method from Math:

Math.pow(base, power);
public class Main {
   public static void main(String[] args) {
      //your code here

   }
}


public class Main {
   public static void main(String[] args) {
      System.out.println(Math.pow(2, 3)); // Displays 8.0
      System.out.println(Math.pow(4, 0.5)); // Displays 2.0
      System.out.println(Math.pow(2.5, 2)); // Displays 6.25
      System.out.println(Math.pow(2.5, -2)); // Displays 0.16
   }
}



PreviousNext

Related