File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes squaring a number and  odd integers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "squaring a number and  odd integers" Watch "squaring a number and  odd integers" New topic
Author

squaring a number and odd integers

jon ladd
Ranch Hand

Joined: Feb 11, 2003
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

Joined: May 05, 2000
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


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Mark Herschberg
Sheriff

Joined: Dec 04, 2000
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

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

Joined: May 05, 2000
Posts: 13974
By the way, the ^ means "exclusive or".
Donald R. Cossitt
buckaroo
Ranch Hand

Joined: Jan 31, 2003
Posts: 401
Running the risk of asking a stupid question: What is the difference between using Math.pow() & Math.exp()? :roll:


doco
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Math.exp(3) = e to the third power.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: squaring a number and odd integers
 
Similar Threads
how this code is working?
To find the Medium
Odd numbers
Listing even and odd numbers
Pulling Integer Values from a String