Java提供了一个工具类Math,其中包含一个abs()的方法实现求绝对值
- 内部实现是通过StrictMath实现的,其中通过对等类提供计算实现
- Math.sqrt() : 计算平方根
- Math.abs() : 取绝对值
- Math.ceil(): 天花板的意思,就是逢余进一
- Math.floor() : 地板的意思,就是逢余舍一
- Math.round(): 四舍五入,float时返回int值,double时返回long值
package cutestFox01;
public class Test007 {
public static void main(String[] args) {
int res = 0;
for(int k=0;k<101;k++) {
res+=k++;
}
System.out.println(res);
}
}