Java math function to convert positive int to negative and negative to positive?

后端 未结 13 2188
暗喜
暗喜 2020-12-01 04:29

Is there a Java function to convert a positive int to a negative one and a negative int to a positive one?

I\'m looking for a reverse function to perfor

13条回答
  •  感动是毒
    2020-12-01 04:48

    Yes, as was already noted by Jeffrey Bosboom (Sorry Jeffrey, I hadn't noticed your comment when I answered), there is such a function: Math.negateExact.

    and

    No, you probably shouldn't be using it. Not unless you need a method reference.

提交回复
热议问题