向上取整用Math.ceil(double a)
向下取整用Math.floor(double a)
例如:
System.out.println(Math.ceil(1.21));
System.out.println(Math.ceil(1.21));
结果:
2.0;
1.0;
本文将详细解释Java中Math.ceil()和Math.floor()方法的功能,通过实例演示如何实现向上取整和向下取整操作,并提供实际应用场景的示例。
向上取整用Math.ceil(double a)
向下取整用Math.floor(double a)
例如:
System.out.println(Math.ceil(1.21));
System.out.println(Math.ceil(1.21));
结果:
2.0;
1.0;
1873
6768
604

被折叠的 条评论
为什么被折叠?