68. JAVA Program to find ‘n’ power ‘n’ of a given number.
How does this program work?
- This program is used to find ‘n’ power ‘n’ of a given number using JAVA.
- The integer entered by the user is stored in variable n.
- After that multiply that number itself using loop.
Here is the code
// n power of n.
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*temp;
}
System.out.println("Result of "+base+" power "+exp+" is "+temp);
}
}