1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
/* Find power using Math.pow This java example shows how to find a power using pow method of Java Math class. */ public class FindPowerExample { public static void main(String[] args) { /* * To find a value raised to power of another value, use * static double pow(double d1, double d2) method of Java Math class. */ //returns 2 raised to 2, i.e. 4 System.out.println(Math.pow(2,2)); //returns -3 raised to 2, i.e. 9 System.out.println(Math.pow(-3,2)); } } /* Output would be 4.0 9.0 */ |
Excellent examples, thank you.
very nice examples…thank you…
request for more… please
if i will use double how could i encode it ?
Like
double a = 2 , b = 3; ?