HR30 Day 17: More Exceptions

1 개요[ | ]

HR30 Day 17: More Exceptions
해커랭크 30 Days of Code
문제 풀이
10-19 Day e
HR30 Day 10: Binary Numbers

HR30 Day 11: 2D Arrays

HR30 Day 12: Inheritance

HR30 Day 13: Abstract Classes

HR30 Day 14: Scope

HR30 Day 15: Linked List

HR30 Day 16: Exceptions - String to Integer

HR30 Day 17: More Exceptions

HR30 Day 18: Queues and Stacks

HR30 Day 19: Interfaces

2 Java[ | ]

//Write your code here
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");
        }
        return (int) Math.pow(n, p);
    }
}

3 PHP[ | ]

<?php
//Enter your code here
class Calculator {
    function power($n,$p) {
        if( $n<0 || $p<0 ) {
            throw new Exception("n and p should be non-negative");
        }
        return pow($n, $p);
    }
}

4 Python[ | ]

#Write your code here
class Calculator(object):
    def power(self, n, p):
        if n<0 or p<0:
            raise Exception("n and p should be non-negative")
        return n**p
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}