-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavalab16.java
More file actions
33 lines (30 loc) · 904 Bytes
/
Copy pathjavalab16.java
File metadata and controls
33 lines (30 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.*;
class myException extends Exception{
public myException (String m){
super (m);
}
}
class Mycalculator{
public void power(int n,int m){
System.out.println("neither of p and n is negative.\n" + m + " power of " + n + "= " + Math.pow(n,m));
}
}
public class javalab16 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Mycalculator ob = new Mycalculator();
try{
System.out.print("Enter number1:");
int n1 = sc.nextInt();
System.out.print("Enter number2:");
int n2 = sc.nextInt();
if(n1<0 || n2<0){
throw new myException("n and p should be non-negative!!!!!!!!!!!!");
}
ob.power(n1, n2);
}
catch(myException obj){
System.out.println(obj.toString());
}
}
}