-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPower.java
More file actions
29 lines (22 loc) · 731 Bytes
/
Power.java
File metadata and controls
29 lines (22 loc) · 731 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
import java.util.Scanner; // #include <iostream>
/* Write a Java program that uses a while loop to compute the power of a number.
Given a base x and an exponent n, calculate x^n. */
// DONE
public class Power {
public static void main(String[] args)
{
Scanner obj = new Scanner(System.in); // input
int result = 1; // multiplication kay mamlay mai 1 rakhna zaroori
System.out.print(" Enter base : ");
int base = obj.nextInt();
System.out.print(" Enter Power : ");
int power = obj.nextInt();
int i = 0;
while (i < power)
{
result = result * base;
i++;
}
System.out.println(" Result : " + result);
}
}