| Author |
Doh! I can't believe I don't know this....Square a number?
|
Will Carpenter
Greenhorn
Joined: Mar 17, 2004
Posts: 26
|
|
What operator do I use to square a number in java? Given: int x = 3; x**2; //is it this? x^2; //maybe this?
|
 |
David Weitzman
Ranch Hand
Joined: Jul 27, 2001
Posts: 1365
|
|
|
There's no primitive for this. "^" is the bitwise exclusive or operator, and ** isn't anything. You'll have to type out x*x or use Math.pow().
|
 |
Parth Sagdeo
Ranch Hand
Joined: Mar 18, 2004
Posts: 40
|
|
|
yep, or more specifically, for all powers, just go Math.pow(base,exponent)
|
 |
Gjorgi Var
Ranch Hand
Joined: Feb 24, 2004
Posts: 85
|
|
And both "base" and "exponent" are of type double...
|
 |
 |
|
|
subject: Doh! I can't believe I don't know this....Square a number?
|
|
|