Systen类
public class Example09 {
/**
*System
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//方法1 System.currentTimeMillis();
long starTime=System.currentTimeMillis();
int sun=0;
for(int i=0;i<100000000;i++){
sun+=i;
}
long endTime=System.currentTimeMillis();
System.out.println("运行的时间为:"+(endTime-starTime)+"毫秒");
方法2 System.arraycopy
int []a={1,2,3,4,5,6};
int[]b={11,22,33,44,55,66};
System.arraycopy(a,2 , b, 3, 3);
for(int i=0;i<b.length;i++){
System.out.println(i+":"+b[i]);
方法3 System.getProperties();s
Properties properties=System.getProperties();
System.out.println(properties);
}
}
Runtime类
public class Example12 {
/**
* Runtime
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Runtime rt=Runtime.getRuntime();
System.out.println("处理器的个数:"+rt.availableProcessors());
System.out.println("空闲内存数量:"+rt.freeMemory()/1024/1024+"M");
System.out.println("最大可用内存数量:"+rt.maxMemory()/1024/1024+"M");
/*
Runtime rt=Runtime.getRuntime();
rt.exec("notepad.exe");
*/
}
}
Math类
public class Example15 {
/**
*注意Π=pi ;
*.abs=绝对值
*.ceil=最小整数
*.
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("计算机绝对的结果:"+Math.abs(-1));
System.out.println("求大于参数的最小整数:"+Math.ceil(5.6));
System.out.println("求小于参数的最大整数:"+Math.floor(-4.2));
System.out.println("求小数四舍五入后的结果:"+Math.round(-4.6));
System.out.println("求两个数的较大值:"+Math.max(2.1,3));
System.out.println("求两个数的较小值:"+Math.min(-2.4, -5));
System.out.println("生成大于等于0.0小于1.0随机数:"+Math.random());
}
}
Random类
import java.util.Random;
public class Example18 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Random s1=new Random();
System.out.println("产生float类型:"+s1.nextFloat());
System.out.println("产生0~100之间的int类型的随机数:"+s1.nextInt(100));
System.out.println("产生double类型的随机数:"+s1.nextDouble());
}
}
包装类
/*
拆想
*/
public class Example20 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Integer num=new Integer(20);
int a=10;
int sum=num.intValue()+a;
System.out.println(a);
}
}
装箱
public class Example19 {
/**
* 包装
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a=20;
Integer in=new Integer(a);
System.out.println(in.toString());
}
}