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

后端 未结 13 2187
暗喜
暗喜 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条回答
  •  猫巷女王i
    2020-12-01 04:54

    We can reverse Java number int or double using this :

    int x = 5;
    int y = -7;
    
    x = x - (x*2); // reverse to negative
    y = y - (y*2); // reverse to positif
    

    Simple algorithm to reverse number :)

提交回复
热议问题