This Java program calculates the power of a number entered by the user. It takes two integer inputs from the user, the base number and the exponent, using the Scanner class.
Overall, this program calculates the power of a number entered by the user using the power() function and displays the result.
import java.util.*; public class Calculate_Power { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the Base Number : "); int base = input.nextInt(); System.out.print("Enter the Exponent Number : "); int exp = input.nextInt(); if (base > 0 && exp > 0 ) System.out.println("Power of the number: "+power(base, exp)); else System.out.println("Please Enter the Positive Numbers.."); } public static int power(int b, int e) { if (e == 0) return 1; int res = b; int t = b; int i, j; for (i = 1; i < e; i++) { for (j = 1; j < b; j++) { res += t; } t = res; } return res; } }
Enter the Base Number : 5 Enter the Exponent Number : 3 Power of the number: 125
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions