Calculate the Power of a Number Java

PROGRAM TO CALCULATE POWER OF A NUMBER


public class Power {

    public static void main(String[] args) {

        int base = 3, exponent = 4;

        long result = 1;

        for (;exponent != 0; --exponent)
        {
            result *= base;
        }

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

OUTPUT
Answer = 81

Comments

Popular posts from this blog

Solve the Sudoku Python

Solve the Sudoku Java

Find Duplicates Java