// This program is to implement 'x raised to n'
// You can even use an in-built function Math.pow()
// to implement the same.
import java.io.*;
public class XRaisedToN
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int num, power, result;
System.out.print("Enter Number:: ");
num = Integer.parseInt(br.readLine());
System.out.print("Enter Power:: ");
power = Integer.parseInt(br.readLine());
// Perform operation
result = 1;
for (int i = 1; i <= power; i++)
{
result = result * num;
}
// Display Result
System.out.println("\n" + num + " raised to " + power + " is:: " + result);
}
}
OUTPUT::
Enter Number:: 2
Enter Power:: 10
2 raised to 10 is:: 1024
// You can even use an in-built function Math.pow()
// to implement the same.
import java.io.*;
public class XRaisedToN
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int num, power, result;
System.out.print("Enter Number:: ");
num = Integer.parseInt(br.readLine());
System.out.print("Enter Power:: ");
power = Integer.parseInt(br.readLine());
// Perform operation
result = 1;
for (int i = 1; i <= power; i++)
{
result = result * num;
}
// Display Result
System.out.println("\n" + num + " raised to " + power + " is:: " + result);
}
}
OUTPUT::
Enter Number:: 2
Enter Power:: 10
2 raised to 10 is:: 1024