Java Math.pow() metode
The java.lang.Math.pow() tiek izmantots, lai atgrieztu pirmā izvirzītā argumenta vērtību otrā argumenta pakāpē. Pow() metodes atgriešanas veids ir dubults.
Sintakse
public static double pow(double a, double b)
Parametrs
a= base b= exponent
Atgriezties
Šī metode atgriež a vērtību b
- Ja otrais arguments ir pozitīvs vai negatīvs Nulle , šī metode atgriezīsies 1.0 .
- Ja otrais arguments nav skaitlis (NaN) , šī metode atgriezīsies NaN .
- Ja otrais arguments ir 1 , šī metode atgriezīs tādu pašu rezultātu kā pirmais arguments .
1. piemērs
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)); } } Izmēģiniet to tagad Izvade:
625.0
2. piemērs
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)); } } Izmēģiniet to tagad Izvade:
0.0013717421124828531
3. piemērs
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)); } } Izmēģiniet to tagad Izvade:
NaN
4. piemērs
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)); } } Izmēģiniet to tagad Izvade:
3.5461138422596736