Find power using Math.pow in Java

Description

The following code shows how to find power using Math.pow.

Example


//ww  w.  ja v  a2 s.  co m
public class Main {

  public static void main(String[] args) {
    // returns 2 raised to 2, i.e. 4
    System.out.println(Math.pow(2, 2));
    // returns -3 raised to 2, i.e. 9
    System.out.println(Math.pow(-3, 2));
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Development »




Java Algorithms
Java Clipboard
Java Compiler
Java Desktop
Java Virtual Machine
Java Math
OS
Random
Java Robot
Java RuntimeMXBean
Java Timer
Java UUID
Java Internationalization