题解 | #取近似值#
取近似值
http://www.nowcoder.com/practice/3ab09737afb645cc82c35d56a5ce802a
import java.util.Scanner;
/写出一个程序,接受一个正浮点数值,输出该数值的近似整数值。
如果小数点后数值大于等于5,向上取整;小于5,则向下取整/
public class DSemo2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); double num = sc.nextDouble(); int i = (int) num; int result = num - i >= 0.5 ? i + 1 : i; System.out.println(result); }
}