This week's book giveaway is in the
General Computing
forum.
We're giving away four copies of
Arduino in Action
and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See
this thread
for details.
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
convert Postiive number to negative..
varun bihani
Ranch Hand
Joined: Aug 11, 2003
Posts: 96
posted
Oct 25, 2006 15:18:00
0
Is there any prebuilt function in
java
that convert positive number to negative number ??
eg, abs() convert negative to positive.. .
<a href="http://www.galaxyweblinks.com" target="_blank" rel="nofollow">www.galaxyweblinks.com</a><br /><a href="http://www.freechatcode.com" target="_blank" rel="nofollow">www.freechatcode.com</a><br /><a href="http://www.onlinefamilytreemaker.com" target="_blank" rel="nofollow">www.onlinefamilytreemaker.com</a>
pascal betz
Ranch Hand
Joined: Jun 19, 2001
Posts: 547
posted
Oct 25, 2006 15:21:00
0
int pos = 10; int neg = 0 - pos;
something like that ? (and you can write it even shorter ...)
pascal
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
I like...
posted
Oct 25, 2006 15:25:00
0
Unary operator -
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award."
~Joe Strummer
sscce.org
sven studde
Ranch Hand
Joined: Sep 26, 2006
Posts: 148
posted
Oct 25, 2006 15:26:00
0
int pos = 10;
int neg = -pos;
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
Oct 25, 2006 17:15:00
0
if you want to guarantee a negative number
Math.abs(number) * -1
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
posted
Oct 25, 2006 17:40:00
0
Originally posted by Michael Dunn:
if you want to guarantee a negative number
Math.abs(number) * -1
Another smart (and handsome) rancher also suggested this
here
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: convert Postiive number to negative..
Similar Threads
Byte
Two's complement question
method to convert positive number to negative
Trying to understand shifting in Java.
Converting Hex to decimal - with a twist
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter