public class PowerDemo
extends java.lang.Object
PowerDemo Java application illustrates the use of
the power and pow methods, which use recursion to
calculate the value of a number raised to an integer power.
Java Source Code for this class: http://www.cs.colorado.edu/~main/applications/PowerDemo.java
| Constructor and Description |
|---|
PowerDemo() |
| Modifier and Type | Method and Description |
|---|---|
static void |
main(java.lang.String[] args)
The
main method activates power and
pow with parameters that are provided by the user. |
static double |
pow(double x,
int n)
Alternate implementation of the
power method. |
static double |
power(double x,
int n)
Computes the value of
x raised to the n power. |
public static void main(java.lang.String[] args)
main method activates power and
pow with parameters that are provided by the user.args - not used in this implementationspublic static double power(double x,
int n)
x raised to the n power.x - any double numbern - the int power to raise x to
Precondition:
If x is zero, then n must be positive.x raised to the n powerjava.lang.IllegalArgumentException - Indicates that x is zero and n is not positive.public static double pow(double x,
int n)
power method.x - basen - exponent