Write a Java program to find the value of one number raised to the power of another number, using Loop.

Two numbers are entered through the keyboard, to find the value of one number raised to the power of another, using loops. 

 

 


 

package forwhile;

import java.util.Scanner;

public class PowerWithLoop {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("Enter Base Number And Exponent");
int basenumber = s.nextInt(), exponent = s.nextInt();
long temp = 1;

for (;exponent != 0; --exponent) {
temp *= basenumber;
}

System.out.println("Power: " + temp);

}
}

Leave a Reply