Class PowerDemo

java.lang.Object
  extended by PowerDemo

public class PowerDemo
extends java.lang.Object

The 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 Summary
PowerDemo()
           
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PowerDemo

public PowerDemo()
Method Detail

main

public static void main(java.lang.String[] args)
The main method activates power and pow with parameters that are provided by the user. The String arguments (args) are not used in this implementation.


power

public static double power(double x,
                           int n)
Computes the value of x raised to the n power.

Parameters:
x - any double number
n - the int power to raise x to
Precondition:
If x is zero, then n must be positive.
Returns:
x raised to the n power
Throws:
java.lang.IllegalArgumentException - Indicates that x is zero and n is not positive.

pow

public static double pow(double x,
                         int n)
Alternate implementation of the power method.