+ 7

Sorry, who can explain me what means math pow in Java?

I'm a freshman

27th Jan 2017, 11:48 AM
Michael55555
Michael55555 - avatar
5 Respostas
+ 9
Thanks very much !!!
27th Jan 2017, 5:59 PM
Michael55555
Michael55555 - avatar
+ 6
pow(x, y) is x multiplied by itself y times. pow(2,3) is 2 * 2 * 2 = 8 pow(2,4) is 2 * 2 * 2 = 16 etc. или просто: возведение в степень
27th Jan 2017, 5:54 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 6
Other notation you may be familiar with, using @abe's example: 2^3 == 2³ == 2*2*2 = 8 In words: Two to the third power.
27th Jan 2017, 6:00 PM
Kirk Schafer
Kirk Schafer - avatar
+ 3
Power of, it's a math class. Java doesn't provide the power operator. (For example, “^” in 3^4). You have to use java.lang.Math.pow(3,4). That method returns type “double”. import java.lang.Math; class T2 { public double square (int n) { return java.lang.Math.pow(n,2); } } class T1 { public static void main(String[] arg) { T2 x1 = new T2(); double m = x1.square(3); System.out.println(m); } } In the above example, we defined 2 classes, T1, T2. “T1” is the main class for this file. Save the file as T1.java. The “T2” class defines one method, the “square”. It takes a “integer” and returns a decimal number of type “double”. (“double” basically means a large decimal number.) In the main class “T1”, the line: T2 x1 = new T2(); It means: x1 is a variable, its type is T2. The value of x1 is a new instance of T2. The line: double m = x1.square(3); Calls the “square” method of “x1”, and assign the result to “m”. In Java, all numbers have a type. All method definition must declare a type for each of their parameter, and declare a type for the thing the method returns.
27th Jan 2017, 11:52 AM
Alex
Alex - avatar
+ 3
a method which returns the value of the first argument raised to the power of the second argument. Math.pow( 2, 3) == 2*2*2 = 8.0 it returns a double
27th Jan 2017, 5:53 PM
abe
abe - avatar