HR30 Day 17: More Exceptions/PHP

1 개요[ | ]

<?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);
    }
}
$myCalculator=new Calculator();
$T=intval(fgets(STDIN));
while($T-->0){
    list($n, $p)  = explode(" ", trim(fgets(STDIN)));
    try{
        $ans=$myCalculator->power($n,$p);
        echo $ans."\n";
    }
    catch(Exception $e){
        echo $e->getMessage()."\n";
    }
}
?>

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}