We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Java Exception Handling
Java Exception Handling
+ 0 comments Here are the solution of Java Exception Handling Hacker Rank Solution
+ 0 comments Here is my solution :
class MyCalculator { /* * Create the method long power(int, int) here. */ public long power(int n,int p) throws Exception{ if(n < 0 || p < 0) throw(new Exception("n or p should not be negative.")); else if(n == 0 && p ==0) throw(new Exception("n and p should not be zero.")); else return (long)Math.pow(n,p); } }
Any suggessions to improve my code . Then you are always welcome :)
+ 0 comments Here is problem solution - https://thecscience.com/hackerrank-java-exception-handling-problem-solution.html
+ 0 comments long power(int n,int p) throws Exception{ if(n<0 || p<0){ throw new Exception("n or p should not be negative."); }else if(n==0 && p==0){ throw new Exception("n and p should not be zero."); }else{ long pow = (long)Math.pow((double)n,(double)p); return (int)pow; } }
+ 0 comments class MyCalculator { public int power(int n, int p) throws Exception { if(n<0 || p<0) throw new Exception("n or p should not be negative."); else if(n==0 && p==0) throw new Exception("n and p should not be zero."); else{ double result = Math.pow(n, p); return (int)result; } } }
Load more conversations
Sort 238 Discussions, By:
Please Login in order to post a comment