Java Program to Calculate the Power of a Number

In this Java program, you’ll learn how to Calculate the Power of a Number using the Java programming language.  

How to Calculate the Power of a Number? 

Example 1: using for loop 

RUN CODE SNIPPET
Java

OUTPUT 

Answer = 25

Example 2: 

RUN CODE SNIPPET
Java

OUTPUT 

Answer = 0.0625

Example 3: using recursion 

RUN CODE SNIPPET
C#

OUTPUT 

Enter the base: 3 
Enter the exponent: 5 
3 to the power 5 is: 243

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this Java program, we will learn how to find the GCD of two numbers using Java.  GCD (Greatest Common...
  • December 3, 2024
In this Java Program, you’ll learn how to swap two numbers using the Java programming language.  How to Swap Two...
  • December 2, 2024
In this Java program , we will learn how to Find Largest Element in an Array in your Java program.   How to Find Largest Element...
  • December 2, 2024