package pack;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;
import java.util.Random;
public class Main {
public static void main(String[] args) throws Exception {
//method1(); //Systemy对象
//method2(); //RunTime对象
//method3(); //Data类
//method4();
//method5();
method6(); //Math类
}
public static void sys(Object obj) {
System.out.println(obj);
}
public static void method1() {
Properties prop = System.getProperties();//Properties是Hashtable的子类,键值
for(Object obj : prop.keySet()) {
sys(obj+":"+prop.get(obj)); //读取系统属性
}
System.setProperty("mykey","myvalue"); //自己设置属性
String os = System.getProperty("os.name");
sys(os); //输出window7
sys(System.currentTimeMillis()); //当前时间
}
public static void method2() throws Exception {
Runtime rt = Runtime.getRuntime();
//rt.exec("F:\\1.txt");
Process p = rt.exec("notepad.exe"); //打开文件
Thread.sleep(4000); //暂停4秒
p.destroy(); //关闭进程
}
public static void method3() {
Date d = new Date();
sys(d);
sys(d.getTime());
SimpleDateFormat sdf = new SimpleDateFormat("y年MM月d日 E hh:mm:ss"); //格式化
sys(sdf.format(d));
}
public static void method4() {
Calendar c = Calendar.getInstance();
sys(c.getTime());
sys(c.get(Calendar.YEAR)+"-"+c.get(Calendar.MONTH)); //获取键得到值
c.add(Calendar.DAY_OF_MONTH, 4);//当前日期加4天
}
public static void method5() {
Calendar c = Calendar.getInstance();
c.set(2014,3,1); //设置时间为
c.add(Calendar.DAY_OF_MONTH, -1); //3.1之前是多少号,即计算此年2月有多少天
c.add(Calendar.YEAR,5); //增加5年
sys(c.get(Calendar.YEAR)); ////获取键得到值
sys(c.get(Calendar.DAY_OF_MONTH));
}
public static void method6() {
sys(Math.E+"---"+Math.PI);
double d = Math.ceil(12.46); //取大于指定数据的最小整数
double d1 = Math.floor(12.46);//取小于指定数据的最大整数
double d2 = Math.round(12.45);//四舍五入
sys(Math.pow(2,3)); //幂运算
sys(d1);
for(int i=0;i<10;i++) {
double d3 = Math.random()*10;
sys(d3);
}
Random r = new Random();
for(int i=0;i<10;i++) {
int d4 = r.nextInt(8); //范围0~8
sys(d4);
}
}
}
原文:http://blog.csdn.net/sjtu_chenchen/article/details/45340779