-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowerCalculation.java
More file actions
23 lines (18 loc) · 874 Bytes
/
PowerCalculation.java
File metadata and controls
23 lines (18 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Importing the Scanner class to take user input
import java.util.Scanner;
public class PowerCalculation {
public static void main(String[] args) {
// Creating a Scanner object to read input from the user
Scanner sc = new Scanner(System.in);
// Prompting the user to enter the base value
System.out.print("Enter the base: ");
double base = sc.nextDouble(); // Reading base input
// Prompting the user to enter the exponent value
System.out.print("Enter the exponent: ");
double exponent = sc.nextDouble(); // Reading exponent input
// Calculating power using the Math.pow() method
double result = Math.pow(base, exponent);
// Displaying the calculated result with two decimal places
System.out.printf("Result: %.2f\n", result);
}
}