四舍五人
System.out.println(Math.round(1.8f));//输出位2
static(静态)方法random()
//: object/Shifting.java
package object;
import static net.util.Print.*;
public class Shifting
{
public static void main(String[] args)
{
double n = Math.random();
System.out.println(n);//产生0-1之间的double数,包括0,不包括1
}
}
本文介绍了Java中Math类的四舍五入方法round()的使用,并演示了如何通过调用静态方法random()来生成0到1之间的随机double数。

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



