Find power of a number
Send Feedback
Write a program to find x to the power n (i.e. x^n). Take x and n from the user. You need to print the answer.
Input format :
Output Format :
Sample Input 1 :
Sample Output 1 :
Sample Input 2 :
Sample Output 2 :
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
int pro=1;
//System.out.print("Enter the base number:");
Scanner s = new Scanner(System.in);
int b = s.nextInt();
// ask for exponent
//System.out.print("Enter the exponent:");
int e = s.nextInt();
//String exponent = s.nextLine();
for (int i=1;i<=e;i++)
{
pro = pro * b;
}
//System.out.println("the power of given number is"+pro);
System.out.println(pro);
}
}
No comments:
Post a Comment