69. JAVA Program to find ‘m’ power ‘n’ of given number.
How does this program work?
- This program is used to find ‘m’ power ‘n’ of given number using JAVA.
- The integers entered by the user is stored in variables m,n.
- After that m will be multiplied by n times using given logic.
Here is the code
//Java Program to find Power of a Number.
import java.util.Scanner;public class power
{
public static void main(String args[] )
{
int base ,exp,temp;
System.out.println("Enter the base number ::");
Scanner obj= new Scanner(System.in );
base = obj.nextInt();
temp=base;
System.out.println("Enter the exponent number ::");
exp = obj.nextInt();
for ( int i=1; i< exp; i++ )
{
temp = temp*base;
}
System.out.println("Result of "+base+" power "+exp+" is "+temp);
}
}