-->

Hello,This is me!

ITEngineer8995

Professional Coder Coding is my passion

Friday, May 29, 2020

Java Program To Calculate Power of a Number using pow() function

  • May 29, 2020
  • by

Java Program To Calculate Power of a Number using pow() function

In this Java Program, we calculate the power of the number using while loop.

The Power (exponent) of the numbers says how many times to use the number in a multiplication. It is written in a small number right and above the base number. 

E.g. the little 3 says to use 10 two times in a multiplication.

                     103 = 10 * 10 * 10 = 1000 

Logic :  result = Math.pow(number, p);

Step 1 : Create the variables named as number and p and store 10 in number and 3 in p.

Step 2 : Create variable result, Use the Math.pow() function to calculate the power of the number and store the result in the variable named result.

Step 3 : Display the result by using the System.out.print.

Program :

public class Power2 
    {
        public static void main(String[] args)
        {
            int number = 10, p =3;
            double result = Math.pow(number, p);
            System.out.println(number+"^"+p+"="+result);
        }
}

Output:

10^3 = 1000

For execution of the same do visit my YouTube Channel:


A blog full of codes of various languages like Java, .net, C, C++ etc with their outputs and some other IT stuff.

0 comments:

Post a Comment

ITEngineer8995
India

SEND ME A MESSAGE

Search This Blog

Powered by Blogger.

Pages