forked from tkggft/JavaClassicInterviewQuestions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathTest.java
More file actions
25 lines (24 loc) · 1.26 KB
/
MathTest.java
File metadata and controls
25 lines (24 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* @auther: WJoe
* @Description: 1. 如果参数为正数,且小数点后第一位>=5,运算结果为参数的整数部分+1。
* 2. 如果参数为负数,且小数点后第一位>5,运算结果为参数的整数部分-1。
* 3. 如果参数为正数,且小数点后第一位<5;或者参数为负数,且小数点后第一位<=5,运算结果为参数的整数部分。
*
* Math类的round()方法的运算结果是一个<=(参数值+0.5)的最大整数
* @Date : 22:02 2018/7/29
*/
public class MathTest {
public static void main(String[] args) {
System.out.println("小数点后第一位=5");
System.out.println("正数:Math.round(11.5)=" + Math.round(11.5));
System.out.println("负数:Math.round(-11.5)=" + Math.round(-11.5));
System.out.println();
System.out.println("小数点后第一位<5");
System.out.println("正数:Math.round(11.46)=" + Math.round(11.46));
System.out.println("负数:Math.round(-11.46)=" + Math.round(-11.46));
System.out.println();
System.out.println("小数点后第一位>5");
System.out.println("正数:Math.round(11.68)=" + Math.round(11.68));
System.out.println("负数:Math.round(-11.68)=" + Math.round(-11.68));
}
}