• + 0 comments
    class MyCalculator {
        public long power(int N,int P) throws Exception {
            if (N ==0&&P==0) throw new Exception("n and p should not be zero.");
            if (N<0||P<0) throw new Exception("n or p should not be negative.");
            int pw = 1;
            for (int i = 0; i < P; i++) pw *= N;
            return pw;
        }
        
    }