How do I raised a number to the power of n?

The static method Math.pow(double a, double b) can be use to raised the value specified in the a to the power of the value specified in b.

package org.kodejava.example.math;

public class PowerExample {

    public static void main(String[] args) {
        double cubeRoot = 5d;

        //
        // Get the cubed number of cube root
        // x cubed = x^3 (multiplication three times)
        //
        double cubed = Math.pow(cubeRoot, 3);
        System.out.println(cubeRoot + " cubed is " + cubed);
    }
}

Our program print the following output:

5.0 cubed is 125.0
Wayan Saryada

Wayan Saryada

A programmer, runner, recreational diver, currently living in the island of Bali, Indonesia. Mostly programming in Java, creating web based application with Spring Framework, JPA, etc. If you need help on Java programming you can hire me on Fiverr.
Wayan Saryada

Leave a Reply