-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPower.java
More file actions
26 lines (22 loc) · 933 Bytes
/
Copy pathPower.java
File metadata and controls
26 lines (22 loc) · 933 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
package Power;
import java.util.Scanner;
public class Power {
static int x, y;
public static void main(String[] args) {
if (args.length > 0) {
if (args.length == 2) {
x = Integer.parseInt(args[0]);
y = Integer.parseInt(args[1]);
System.out.println(" " + x + " ^ " + y + " = " + Math.pow(x, y));
} else
System.out.println(" [!] Commandline Arguments must be two integers: [x (base)], [y (power)]");
}
Scanner scanner = new Scanner(System.in);
System.out.print(" [<-] Enter the base integer value: ");
int x = scanner.nextInt();
System.out.print(" [<-] Enter the exponent integer value: ");
int y = scanner.nextInt();
scanner.close(); // closing the stream as it's not needed anymore.
System.out.println("[->] " + x + " ^ " + y + " = " + Math.pow(x, y));
}
}