5 在java等于多少,java基础面试题之Java中的Math. round(-1. 5)等于多少
Java 中的 Math. round(-1. 5) 等于多少?
答案:-1
/**
* Returns the closest {@code long} to the argument, with ties
* rounding to positive infinity.
*
*
Special cases:
*
- If the argument is NaN, the result is 0.
*
- If the argument is negative infinity or any value less than or
* equal to the value of {@code Long.MIN_VALUE}, the result is
* equal to the value of {@code Long.MIN_VALUE}.
*
- If the argument is positive infinity or any value greater than or
* equal to the value of {@code Long.MAX_VALUE}, the result is
* equal to the value of {@code Long.MAX_VALUE}.
*
* @param a a floating-point value to be rounded to a
* {@code long}.
* @return the value of the argument rounded to the nearest
* {@code long} value.
* @see java.lang.Long#MAX_VALUE
* @see java.lang.Long#MIN_VALUE
*/
看代碼的定義就是返回最接近參數的long型整數,如果有兩個,就返回大的那個;
通俗點直接+0.5后取整就是要的結果。
總結
以上是生活随笔為你收集整理的5 在java等于多少,java基础面试题之Java中的Math. round(-1. 5)等于多少的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 随机钱数,PHP 仿微信红包金额
- 下一篇: 马斯克前女友就“马扎笼斗&r