- 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 number
Read the base and exponent values from the user. Multiply the base number by itself and multiply the resultant with base (again) repeat this n times where n is the exponent value.
2 ^ 5 = 2 X 2 X 2 X 2 X 2 (5 times)
Example
import java.util.Scanner; public class PowerOfNumber { public static void main(String args[]){ Scanner sc = new Scanner(System.in); System.out.println("Enter the base number ::"); int base = sc.nextInt(); int temp = base; System.out.println("Enter the exponent number ::"); int exp = sc.nextInt(); for (int i=1; i<exp; i++){ temp = temp*temp; } System.out.println("Result of "+base+" power "+exp+" is "+temp); } }
Output
Enter the base number :: 12 Enter the exponent number :: 2 Result of 12 power 2 is 144
- Related Articles
- Calculate the Power of a Number in Java Program
- Java program to calculate the power 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
- C++ Program to Calculate Power of a Number
- C program to calculate power of a given number
- Java Program to calculate the power using recursion
- Java program to calculate the GCD of a given number using recursion
- Calculate the power on a BigInteger in Java
- Golang Program to Calculate The Power using Recursion
- How to calculate Power of a number using recursion in C#?
- Java program to calculate the factorial of a given number using while loop
- C++ Program to Calculate Power Using Recursion
- 8085 program to find nth power of a number

Advertisements