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
    6

    Default

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

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,525
    Blog Entries
    7
    Rep Power
    20

    Default

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

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  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 online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,525
    Blog Entries
    7
    Rep Power
    20

    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
    cenosillicaphobia: the fear for an empty beer glass

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, 06:19 AM
  5. Positive Divisor of int
    By starchildren3317 in forum New To Java
    Replies: 16
    Last Post: 02-20-2009, 03: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
  •