# Power a Number in Java

Oct 27, 2021

Machine Problem

Write a Java program that will ask the user to give base and exponent number and then the program will compute the power of the number.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My mobile number here in the Philippines is 09173084360.

``````package test;

import java.util.Scanner;

/*
* Power_A_Number.java
*
* Jake Rodriguez Pomperada, MAED-IT, MIT
* Bacolod City, Negros Occidental Philippines
*
* Machine Problem
*
* Write a Java program that will ask the user to give base and exponent number
* and then the program will compute the power of the number.
*
*/

public class Power_A_Number {

public static void main(String args[]){

Scanner input = new Scanner(System.in);

System.out.println();
System.out.println("\tPower a Number in Java");
System.out.println();
System.out.print("\tGive base number : ");
int base = input.nextInt();
int temp = base;
System.out.print("\tGive exponent number : ");
int exp = input.nextInt();

for (int i=1; i<exp; i++){
temp = temp*temp;
}
System.out.println();
System.out.println("\tThe Result is "+base+" power "+exp+" is "+temp);
System.out.println();
System.out.print("\tEnd of Program \n");
System.out.println();
input.close();
}
}``````