Java Number Power pow(int x, int y)

Here you can find the source of pow(int x, int y)

Description

Positive integer powers.

License

Open Source License

Declaration

public static int pow(int x, int y) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static final int[][] INTEGER_POWERS = new int[50][50];

    /**/*from   w  ww  .ja  va2 s.co  m*/
     * Positive integer powers.
     */
    public static int pow(int x, int y) {
        if ((x >= 0) && (x < 50) && (y < 50)) {
            return INTEGER_POWERS[x][y];
        } else {
            switch (y) {
            case 0:
                return 1;
            case 1:
                return x;
            case 2:
                return x * x;
            case 3:
                return x * x * x;
            default:
                if (y < 0) {
                    throw new IllegalArgumentException("y " + y + " < 0");
                } else {
                    for (int i = 1; i < y; i++) {
                        x *= x;
                    }
                    return x;
                }
            }
        }
    }
}

Related

  1. pow(int i, int pow)
  2. pow(int leftOp, int rightOp)
  3. pow(int n, int p)
  4. pow(int number, int power)
  5. pow(int value, int exp)
  6. pow(int[] arr, double p)
  7. pow(Integer a, Integer b)
  8. pow(long base, long exp)
  9. pow(long n, long pow)