aspose file tools*
The moose likes Beginning Java and the fly likes Doh! I can't believe I don't know this....Square a number? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Doh! I can Watch "Doh! I can New topic
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doh! I can't believe I don't know this....Square a number?