Metoda Java Math.pow().
The java.lang.Math.pow() se uporablja za vrnitev vrednosti prvega argumenta, povišane na potenco drugega argumenta. Vrsta vrnitve metode pow() je dvojna.
Sintaksa
public static double pow(double a, double b)
Parameter
a= base b= exponent
Vrnitev
Ta metoda vrne vrednost a b
- Če je drugi argument pozitiven ali negativen Nič , se bo ta metoda vrnila 1.0 .
- Če drugi argument ni število (NaN) , se bo ta metoda vrnila NaN .
- Če je drugi argument 1 , bo ta metoda vrnila enak rezultat kot prvi argument .
Primer 1
public class PowExample1 { public static void main(String[] args) { double x = 5; double y = 4; //returns 5 power of 4 i.e. 5*5*5*5 System.out.println(Math.pow(x, y)); } } Preizkusite zdaj Izhod:
625.0
Primer 2
public class PowExample2 { public static void main(String[] args) { double x = 9.0; double y = -3; //return (9) power of -3 System.out.println(Math.pow(x, y)); } } Preizkusite zdaj Izhod:
0.0013717421124828531
Primer 3
public class PowExample3 { public static void main(String[] args) { double x = -765; double y = 0.7; //return NaN System.out.println(Math.pow(x, y)); } } Preizkusite zdaj Izhod:
NaN
Primer 4
public class PowExample4 { public static void main(String[] args) { double x = 27.2; double y = 1.0; // Second argument is 1 so output is 27.2 System.out.println(Math.pow(x, y)); } } Preizkusite zdaj Izhod:
3.5461138422596736