@@ -0,0 +1,1865 @@
+package thirty_days_of_code;%0D%0A%0D%0Aimport java.util.Scanner;%0D%0A%0D%0A/*%0D%0A * Problem Statement:%0D%0A * Create a class Calculator which consists of a single method power(int,int).%0D%0A * This method takes two integers, n and p, as parameters and finds np. If%0D%0A * either n or p is negative, then the method must throw an exception which says%0D%0A * %22n and p should be non-negative%22.%0D%0A * %0D%0A * Code for handling Input/Output is already provided in the editor. Please read%0D%0A * the partially completed code in the editor and complete it.%0D%0A * %0D%0A * Note: The class Calculator mustn't be public.%0D%0A * %0D%0A * No need to worry about constraints, there won't be any overflow if your code%0D%0A * is correct.%0D%0A * %0D%0A * Input Format: %0D%0A * First line contains T, the number of test cases. Next T lines contain two%0D%0A * integers n and p separated by a space.%0D%0A * %0D%0A * Output Format: %0D%0A * Output T lines. For each test case if n and p are positive then print np else%0D%0A * print %22n and p should be non-negative%22 without quotes.%0D%0A * %0D%0A * Sample Input: %0D%0A * 4%0D%0A * 3 5%0D%0A * 2 4%0D%0A * -1 -2%0D%0A * -1 3%0D%0A * %0D%0A * Sample Output: %0D%0A * 243%0D%0A * 16%0D%0A * n and p should be non-negative%0D%0A * n and p should be non-negative%0D%0A */%0D%0Apublic class Exceptions %7B%0D%0A%0D%0A%09public static void main(String%5B%5D argh) %7B%0D%0A%09%09Scanner in = new Scanner(System.in);%0D%0A%09%09int T = in.nextInt();%0D%0A%09%09while (T-- %3E 0) %7B%0D%0A%09%09%09int n = in.nextInt();%0D%0A%09%09%09int p = in.nextInt();%0D%0A%09%09%09Calculator myCalculator = new Calculator();%0D%0A%09%09%09try %7B%0D%0A%09%09%09%09int ans = myCalculator.power(n, p);%0D%0A%09%09%09%09System.out.println(ans);%0D%0A%0D%0A%09%09%09%7D catch (Exception e) %7B%0D%0A%09%09%09%09System.out.println(e.getMessage());%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%09in.close();%0D%0A%09%7D%0D%0A%7D%0D%0A%0D%0Aclass Calculator %7B%0D%0A    %0D%0A    public int power(int n, int p) throws ArithmeticException %7B%0D%0A        if (n %3C 0 %7C%7C p %3C 0) %7B%0D%0A            throw new ArithmeticException(%22n and p should be non-negative%22);%0D%0A        %7D%0D%0A        return (int) Math.pow(n, p);%0D%0A    %7D%0D%0A%7D

Add Exceptions