Skip to main content

Posts

Showing posts with the label Day 17: More Exceptions Hackerrank Solution Java

Day 17: More Exceptions Hackerrank Solution Java

 Day 17: More Exceptions Hackerrank Solution Java For Explanation Check Video: Sample Input 4 3 5 2 4 -1 -2 -1 3 Sample Output 243 16 n and p should be non-negative n and p should be non-negative Code: 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" );         } else {              return  ( int )Math.pow(n,p);         }     } } class  Solution{      public   static   void  main(St...