Power of Number in Java Program. The power (or exponent) of a number indicates how many times it should be multiplied. It’s printed above and to the right of the basic number as a tiny number. In this case, the small “2” indicates that 8 should be multiplied twice: 82 = 8*8 = 64.

class Main

{

public static void main(String[] args)

{

int base = 5, exponent = 3;

long result = 1;

while (exponent != 0)

{

result *= base;

--exponent;

}

System.out.println("Answer = " + result);

}

}

Output:

Answer = 125

## What is Long int in Java

A 64-bit two’s complement integer is the long data type. The signed long has a value of -263 at its lowest point and 263-1 at its highest point. You can express an unsigned 64-bit long with a minimum value of 0 and a maximum value of 264-1 with the long data type in Java SE 8 and later.

## What is While Loop and How to Execute for Power of Number in Java

The while loop in Java is a control flow statement that allows code to be repeated based on a Boolean condition using this method we can calculate power of number in java. The while loop is similar to a looping if statement. If the condition evaluates to true, the body of the loop will be executed, and we will proceed to the update expression.

## Power of Number in Java Program for Calculation

In Java, the power function is used to calculate a number that has been raised to the power of another number. This method takes two parameters and returns the first parameter’s value multiplied by the second parameter’s value.

An exponent is a number or letter that is written above and to the right of the base in a mathematical statement. It denotes that the base will be raised to a given level of strength. The base is x, while the exponent or power is n to calculate power of number in java.

## Similar Programs

Java Program to print the gcd hcf recursion

Java program to print the Armstrong number between two intervals

how to calculate percentage of marks of 5 subjects

Java program to print the factor of number

C Program to execute structure for dynamic allocation memory

C Program to print power of a number

Java program to calculate standard deviation

Java program to count the number of vowels and consonant in a sentence

Java program to sort the string in dictionary order

Python program to print the typecasting int string and float value

Python program to find the variable type using type casting

Lower Triangular Matrix in Java Program

Java program to remove whitespace

Python program to print the multiple values in a single line

Python program to print the single value into multiple variables

Python program to unpack the list and tuples

Python program to merge variables using + operator

Python program to print the string using function

Python program to create function inside a function

Python program to print the string using global declaration method