题解 | #取近似值# 考虑负浮点数版本
取近似值
https://www.nowcoder.com/practice/3ab09737afb645cc82c35d56a5ce802a
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
double a = in.nextDouble();
System.out.println(a < 0 ? (int)(a-0.5) : (int)(a+0.5));
}
}
}