取近似值
取近似值
http://www.nowcoder.com/questionTerminal/3ab09737afb645cc82c35d56a5ce802a
import java.util.Scanner; /** * 题目描述 * 写出一个程序,接受一个正浮点数值,输出该数值的近似整数值。如果小数点后数值大于等于5,向上取整;小于5,则向下取整。 */ public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double doubleNum = scanner.nextDouble(); int intNum =(int) doubleNum; if(doubleNum - intNum >=0.5 && doubleNum - intNum < 1){ intNum ++; } System.out.println(intNum); } }