Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. I check, compile and run every program. Contact me at: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


6,846 questions

9,748 answers

573 users

How to calculate power of a number in Java

2 Answers

0 votes
package javaapplication1;

public class JavaApplication1 {
  
    public static void main(String[] args) {
         
        int exponent = 4, n = 2, i = 1, power = 1;
 
        while (i <= exponent)
        {
            power = power * n;
            i++;
        }
        
        System.out.format("%d ^ %d = %d\n", n ,exponent, power);
    }
}
    
/*
run:
   
2 ^ 4 = 16
    
*/

 




answered May 22, 2017 by avibootz
0 votes
package javaapplication1;

public class JavaApplication1 {
  
    public static void main(String[] args) {
         
        double exponent = 4, n = 2;
 
        double power = Math.pow(n, exponent);
        
        System.out.format("%.2f ^ %.2f = %.2f\n", n ,exponent, power);
    }
}
    
/*
run:
   
2.00 ^ 4.00 = 16.00
    
*/

 




answered May 22, 2017 by avibootz
...