Sort by

recency

|

623 Discussions

|

  • + 0 comments
    class Calculator:
        def power(self, n:int, p:int) -> int:
            assert n >= 0 and p >= 0, "n and p should be non-negative"
            
            return n**p
    
  • + 0 comments
    class Calculator:
        def power(self, n, p):
            if n < 0 or p < 0:
                raise Exception("n and p should be non-negative")
            return n ** p  
    
  • + 0 comments

    Python:

    class Calculator:
        def init(self): pass
    
        def power(self,n,p):
        if n < 0 or p < 0:
            raise ValueError('n and p should be non-negative') 
        return n ** p
    
  • + 0 comments

    // Java code import java.util.; import java.io.;

    //Write your code here class Calculator{ public int power(int n, int p){ if(n<0 || p<0) // check negative number throw new RuntimeException("n and p should be non-negative"); return (int)Math.pow(n, p); } }

    class Solution{

  • + 0 comments
    class Calculator {
        
        int power(int n, int p) throws Exception{
            
            if (n < 0 || p < 0)
                throw new Exception("n and p should be non-negative");
            else
                return (int)Math.pow(n, p);
            
        }
        
    }