Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

squaring a number and odd integers

 
jon ladd
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could do this:
double d = Math.pow(myNum, 2.0d);
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, the ^ means "exclusive or".
 
Donald R. Cossitt
buckaroo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Math.exp(3) = e to the third power.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic