- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to calculate the power of a Given number using recursion
You can calculate the power where the base and exponent are given, using recursion as shown in the following program.
Example
import java.util.Scanner; public class PowerUsingRecursion { public static int power(int base, int exp){ if (exp !=0){ return (base * power(base, exp-1)); }else { return 1; } } public static void main(String args[]){ Scanner sc = new Scanner(System.in); System.out.println("Enter the base number ::"); int base = sc.nextInt(); System.out.println("Enter the exponent number ::"); int exp = sc.nextInt(); System.out.println(power(base, exp)); } }
Output
Enter the base number :: 5 Enter the exponent number :: 5
- Related Articles
- Java Program to calculate the power using recursion
- Java program to calculate the GCD of a given number using recursion
- Golang Program to Calculate The Power using Recursion
- C++ Program to Calculate Power Using Recursion
- How to calculate Power of a number using recursion in C#?
- Java program to calculate the power of a number
- Java program to find the factorial of a given number using recursion
- C program to calculate power of a given number
- C++ program to Calculate Factorial of a Number Using Recursion
- Calculate the Power of a Number in Java Program
- Java program to calculate the factorial of a given number using while loop
- Swift program to find the reverse of a given number using recursion
- Swift Program to Calculate the Power of a Number
- Haskell Program to Calculate the Power of a Number
- Kotlin Program to Calculate the Power of a Number

Advertisements