Results 1 to 5 of 5
  1. #1
    aconti is offline Member
    Join Date
    May 2011
    Posts
    39
    Rep Power
    0

    Default convert negative int to positive

    Hello,

    how can I convert a variable from negative to positive.

    Ideally I just want to show the value in positive but would also like to know how can I make the variable stored as positive.

    Thanks !

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    7

    Default

    Multiply it by -1?
    Get in the habit of using standard Java naming conventions!

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,044
    Blog Entries
    7
    Rep Power
    23

    Default

    Java Code:
    int negative= ...
    int positive= -negative;
    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  4. #4
    aconti is offline Member
    Join Date
    May 2011
    Posts
    39
    Rep Power
    0

    Default

    Thanks all worked fine

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,044
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by aconti View Post
    Thanks all worked fine
    Beware that the value Integer.MIN_VALUE doesn't have a postive counterpart in the int domain, but that's how binary twos-complements work ...

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. Negative,Positive and Zero
    By dipowo in forum New To Java
    Replies: 2
    Last Post: 04-04-2011, 05:49 AM
  2. Return positive values only
    By DomBrown in forum New To Java
    Replies: 14
    Last Post: 03-31-2011, 07:48 PM
  3. Sum positive numbers using 10 inputs from user
    By pvictory1 in forum New To Java
    Replies: 15
    Last Post: 10-10-2010, 01:30 AM
  4. Help with syntax to reverse a positive integer
    By sonny in forum New To Java
    Replies: 14
    Last Post: 02-27-2010, 07:19 AM
  5. Positive Divisor of int
    By starchildren3317 in forum New To Java
    Replies: 16
    Last Post: 02-20-2009, 04:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •