Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

negative integer

 
Peter Straw
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to turn a positive int or Integer into a negative value of the same amount eg. +60 into -60?
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Multiply by -1.
 
Junilu Lacar
Bartender
Pie
Posts: 7314
45
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the unary - operator does it:

Integer is a wrapper class and is immutable. You'd have to do something like this:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic