Power of given number
previous NextExample
import java.util.Scanner;
class Raj
{
public static void main(String[] args) {
int power;
int num;
int i = 1;
int sum = 1;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number:");
num = sc.nextInt();
System.out.print("Enter power:");
power = sc.nextInt();
while(i<=power)
{
sum = sum*num;
i++;
}
System.out.println(num+" to the power "+power+" is: "+sum);
}
}
Output :
Enter a number: 3 Enter power : 3 3 to the power 3 is: 27