-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathPower.java
More file actions
29 lines (24 loc) · 758 Bytes
/
Power.java
File metadata and controls
29 lines (24 loc) · 758 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
/**
* @author @MadhavBahl
* @date 18/01/2019
*/
import java.util.Scanner;
public class Power {
public static double findPower (double a, double n) {
if (n <= 0)
return 1;
return a*findPower(a, n-1);
}
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
System.out.println("/* ===== Exponent ===== */");
// Input the base and exponent
System.out.print("\nEnter a: ");
double a = input.nextDouble();
System.out.print("Enter n: ");
double n = input.nextDouble();
// Find and print the power
double power = findPower(a, n);
System.out.println(a + " raised to the power " + n + " is = " + power);
}
}