Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# squaring a number and odd integers

Ranch Hand
Posts: 53
what symbol is used to square a number I thought it would be this symbol ^ but that does not work from what I've try. Also is it possible to just have display odd integers. Even if some one new a site that would explain it that would be great.
thnxs

Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
Take a look at the Math class.
Odd integers are the ones that have a remainder when you divide them by 2.
If ( x % 2 == 1 ) // then it's odd

Mark Herschberg
Sheriff
Posts: 6037
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/opsummary.html might help (but there's no square operator). Of course, you can always multiply the number by itself.
--Mark

Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
You could do this:
double d = Math.pow(myNum, 2.0d);

Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
By the way, the ^ means "exclusive or".

Donald R. Cossitt
buckaroo
Ranch Hand
Posts: 401
Running the risk of asking a stupid question: What is the difference between using Math.pow() & Math.exp()? :roll:

Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
Math.exp(3) = e to the third power.