In this article, we will discuss the concept of program to Calculate power of a number using recursion in Java language
In this post, we will learn how to find the power of a number using recursive function in Java language
Program 1
import java.util.Scanner; class CalcPower{ public static void main (String args[]){ Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("Enter the base number: "); int base=scan.nextInt(); //read base number from user System.out.print("Enter the exponant number: "); int exp=scan.nextInt(); //read exponent number from user int result=find_Power(base, exp); //call the recursive function System.out.println("The power is "+result); //display the result } public static int find_Power(int base, int exp){ //recursive function for calculating power if(exp !=0){ return (base*find_Power(base,exp-1)); } else{ return 1; } } }
When the above code is executed, it produces the following results
Enter the base number: 4 Enter the exponent number: 5 The power is 1024
In the above program, the user can enter the value for the base and powerValue (for raised times). we can find the power of a given number using a recursive function find_Power().
The recursive function used to multiples the bases with itself for powerValue times.
Explanation
3^4=81
thereafter
4*4*4*4*4=1024
Similar post
find the power of a number in C++ using recursion
find the power of a number in C using recursion
find the power of a number in Python using recursion
Suggested for you
C program to find a number is even or odd using the function
C program to separate Odd and Even numbers from an array
C program to Electricity bill calculation using the function
C program to display all even and odd numbers from 1 to n
C program display odd and even numbers without if statements
C program to calculate the sum of odd and even numbers
C program to find whether a number is even or odd
C++ program to find a number is even or odd using the function
C++ program to separate Odd and Even numbers from an array
C++ program to display all even and odd numbers from 1 to n
C++ program calculate Average of odd and even numbers in an array
C++ program to calculate the sum of odd and even numbers
C++ program to find whether a number is even or odd
Java program to find a number is even or odd using the method
Java program to separate Odd and Even numbers from an array
Java program to display all even and odd numbers from 1 to n
Java program display odd and even numbers without if statements
Java program to calculate the sum of odd and even numbers
Java program to find whether a number is even or odd
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…