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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Java
  3. Exception Handling
  4. Java Exception Handling
  5. Discussions

Java Exception Handling

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 238 Discussions, By:

recency

Please Login in order to post a comment

  • KRITIKSAURAV33
    1 week ago+ 0 comments

    Here are the solution of Java Exception Handling Hacker Rank Solution

    0|
    Permalink
  • pmsanjay2003
    4 weeks ago+ 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 :)

    1|
    Permalink
  • poonamdeorasurp1
    1 month ago+ 0 comments

    Here is problem solution - https://thecscience.com/hackerrank-java-exception-handling-problem-solution.html

    0|
    Permalink
  • premkhodke_99
    1 month ago+ 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|
    Permalink
  • subhamde568
    2 months ago+ 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;
            }
        }
    }
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy