标签:oid name ring string color tran 必须 理解 setname
java.lang.Math类
里面提供了许多静态方法,供完成数学相关的操作
方法:
public static int abs(double a)//取绝对值
public static double ceil(double a)//向上取整 12.1-->13(像x轴正方向取整)-10.8-->-10.0注意返回值是double类型的
public static double floor(double a)//向下取整 12.1-->12
public static long round(double a)//四舍五入
练习
package commonclass;
//练习Math工具类
//题目:计算-10.8~5.9之间,绝对值大于6或者小于2.1的整数个数
public class PracticeMath01 {
public static void main(String[] args) {
double min = -10.8;
double max = 5.9;
int num = 0;
for (int i = (int) min; i < max; i++) {
if (Math.abs(i) >6 ||Math.abs(i) <= 2){
System.out.print(i+"\t");
num++;
}
}
System.out.println(" \r");
System.out.println("-10.8~5.9之间,绝对值大于6或者小于2.1的整数个数有"+num+"个!");
}
}
标签:oid name ring string color tran 必须 理解 setname
原文地址:https://www.cnblogs.com/orzjiangxiaoyu/p/13454356.html