Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
package com.javaaid.hackerrank.solutions.languages.java.exceptionhandling;

/**
* @author Kanahaiya Gupta
* @RakeshPatil95
*
*/
public class JavaExceptionHandling {
int power(int n, int p) throws Exception {

if (n < 0 || p < 0) {
throw new Exception("n and p should be non-negative");
} else {
return (int) Math.pow(n, p);
}

}

class MyCalculator
{
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.");
return (long) Math.pow(n,p);
}
}