A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Doh! I can't believe I don't know this....Square a number?
Joined: Mar 17, 2004
Mar 21, 2004 19:54:00
What operator do I use to square a number in
Given: int x = 3;
x**2; //is it this?
x^2; //maybe this?
Joined: Jul 27, 2001
Mar 21, 2004 20:19:00
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().
Joined: Mar 18, 2004
Mar 24, 2004 01:33:00
yep, or more specifically, for all powers, just go Math.pow(base,exponent)
Joined: Feb 24, 2004
Mar 27, 2004 13:56:00
And both "base" and "exponent" are of type double...
I agree. Here's the link:
subject: Doh! I can't believe I don't know this....Square a number?
Can you clarify Assignment 1.6 pls?
Grains - algorithm
[easy]Find the number
Need help making my implementation faster
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015