黑马程序员技术交流社区
标题:
Math.System.Random三个类的代码小结
[打印本页]
作者:
Morrfree
时间:
2015-8-13 22:25
标题:
Math.System.Random三个类的代码小结
public class TestSystem {
/**
* @param args
*/
public static void main(String[] args) {
//返回当前时间毫秒值
long l = System.currentTimeMillis();
System.out.println(l);
//获取当前系统的属性值
System.out.println(System.getProperties());
}
}
import java.util.Random;
public class TestRandom {
/**
* @param args
*/
public static void main(String[] args) {
Random r = new Random();
Random r1 = new Random(646165);
Random r2 = new Random(646165);
double double1 = r.nextDouble();
double double2 = r1.nextDouble();
double double3 = r2.nextDouble();
System.out.println(double1);
System.out.println(double2);
System.out.println(double3);
System.out.println(r.nextInt(30)+90);
}
}
public class TestMath1 {
/**
* 需求:使用Math类中的方法,Math中的类都是静态的,可以由类名直接调用.
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//圆周率
System.out.println(Math.PI);
//自然对数的底数
System.out.println(Math.E);
//求绝对值
int i = -1;
System.out.println(Math.abs(i));
//天花板,向上取整
double d = 1.4234223;
System.out.println(Math.ceil(d));
//地板,向下取整
System.out.println(Math.floor(d));
//四舍五入
System.out.println(Math.round(d));
//a的b次幂
System.out.println(Math.pow(d, i));
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2