HackerRank Day 17 More Exceptions 30 days of code solution YASH PAL, 31 July 202413 October 2025 HackerRank Day 17 More Exceptions solution – In this HackerRank Day 17 More Exceptions 30 days of code problem set, we need to develop a program that can take two input integers and then we need to print the power of that inputs on the output screen and if the numbers are negative integers then we need to print the message that inputs are needed to positive numbers.ObjectiveYesterday’s challenge taught you to manage exceptional situations by using try and catch blocks. In today’s challenge, you will practice throwing and propagating an exception. Check out the Tutorial tab for learning materials and an instructional video. TaskWrite a Calculator class with a single method: int power(int,int). The power method takes two integers,n and p, as parameters and returns the integer result of np. If either n or p is negative, then the method must throw an exception with the message: n and p should be non-negative.Note: Do not use an access modifier (e.g.: public) in the declaration for your Calculator class.Input FormatInput from stdin is handled for you by the locked stub code in your editor. The first line contains an integer, T, the number of test cases. Each of the T subsequent lines describes a test case in 2 space-separated integers that denote n and p, respectively. ConstraintsNo Test Case will result in overflow for correctly written code.Output FormatOutput to stdout is handled for you by the locked stub code in your editor. There are T lines of output, where each line contains the result of np as calculated by your Calculator class’ power method.Problem solution in Python 2 programming.#Write your code here class Calculator: def power(self, n, p): if (n < 0 or p < 0): raise Exception("n and p should be non-negative") else: return n**p Problem solution in Python 3 programming.#Write your code here class Calculator: def power(self,n, p): if n < 0 or p < 0: raise Exception("n and p should be non-negative") else: return pow(n,p)Problem solution in java programming.class Calculator{ public 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); } }Problem solution in c++ programming.//Write your code here class Calculator { public: int power(int n, int p){ if(n < 0 || p < 0){ throw invalid_argument("n and p should be non-negative"); } return pow(n, p); } };Problem solution in Javascript programming.//Write your code here function Calculator() { this.power = function(n, p) { if (n < 0 || p < 0) throw "n and p should be non-negative"; var ans = 1; for (i = 0; i < p; i++) { ans *= n; } return ans; } } 30 days of code coding problems solutions HackerRank