题解 | #取近似值#
取近似值
https://www.nowcoder.com/practice/3ab09737afb645cc82c35d56a5ce802a
思路:
double类型转long类型,可直接调用Math.round()方法
代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextDouble()) {
double db = sc.nextDouble();
System.out.println(Math.round(db));
}
}
}
#华为机试HJ7#