将浮点数的小数部分和整数部分分离,然后根据小数部分来判断四舍五入的结果
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
double target = sc.nextFloat();
int res = (int)target;
target = target - res;
System.out.println(res += target >= 0.5?1:0);
}
}
}