使負數爲正 - Make a negative number positive

問題:

I have a Java method in which I'm summing a set of numbers.我有一個Java方法,其中對一組數字求和。 However, I want any negatives numbers to be treated as positives.但是,我希望將任何負數都視爲正數。 So (1)+(2)+(1)+(-1) should equal 5.所以(1)+(2)+(1)+(-1)應該等於5。

I'm sure there is very easy way of doing this - I just don't know how.我敢肯定有很簡單的方法可以做到-我只是不知道怎麼做。


解決方案:

參考一: https://en.stackoom.com/question/24Na
參考二: https://stackoom.com/question/24Na
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章