"HR30 Day 17: More Exceptions/Java"의 두 판 사이의 차이

(새 문서: ==개요== * HR30 Day 17: More Exceptions <source lang='java'> import java.util.*; import java.io.*; </source> <source lang='java'> //Write your code here class Calculator {...)
 
잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(다른 사용자 한 명의 중간 판 하나는 보이지 않습니다)
2번째 줄: 2번째 줄:
* [[HR30 Day 17: More Exceptions]]
* [[HR30 Day 17: More Exceptions]]


<source lang='java'>
<syntaxhighlight lang='java'>
import java.util.*;
import java.util.*;
import java.io.*;
import java.io.*;
</source>
</syntaxhighlight>
<source lang='java'>
<syntaxhighlight lang='java'>
//Write your code here
//Write your code here
class Calculator {
class Calculator {
16번째 줄: 16번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>
<source lang='java'>
<syntaxhighlight lang='java'>
class Solution{
class Solution{


40번째 줄: 40번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>
[[분류: 30 Days of Code]]
[[분류: HR30 Java]]

2021년 10월 12일 (화) 23:53 기준 최신판

개요[ | ]

import java.util.*;
import java.io.*;
//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);
    }
}
class Solution{

    public static void main(String[] args) {
    
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while (t-- > 0) {
        
            int n = in.nextInt();
            int p = in.nextInt();
            Calculator myCalculator = new Calculator();
            try {
                int ans = myCalculator.power(n, p);
                System.out.println(ans);
            }
            catch (Exception e) {
                System.out.println(e.getMessage());
            }
        }
        in.close();
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}