Java program to calculate value using base and exponent ( power value ) using for loop


Program
import java.util.*; public class ValueUsingPower { public static void main(String[] args) { Scanner s=new Scanner(System.in); int result=1; System.out.println("Enter the Base Value"); int base = s.nextInt(); System.out.println("Enter the Exponent Value"); int exponent = s.nextInt(); for(int i=1;i<=exponent;i++) { result=result*base; } System.out.println("Result = " + result); } }
Input
Output