-
Notifications
You must be signed in to change notification settings - Fork 0
/
qb92.java
31 lines (28 loc) · 956 Bytes
/
qb92.java
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
// QB 92
//Pass Command ine argument for x & y.
class qb92 {
public static void power(int x, int y) {
int result = 1;
for (int i = 0; i < y; i++) {
result = result * x;
}
System.out.println(y + " power of " + x + " is " + result);
}
public static void main(String[] args) {
try {
int x = Integer.parseInt(args[0]);
int y = Integer.parseInt(args[1]);
if (y < 0) {
throw new IllegalArgumentException("Negative value for y is invalid");
} else {
power(x, y);
}
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Must Enter Two Argument ");
} catch (NumberFormatException e) {
System.out.println("Number must be Integer");
} catch (IllegalArgumentException e) {
System.out.println("Value of y is negative ");
}
}
}