/**
* @author 饶永超 郑州大学软件学院
* 本程序主要功能是练习使用System类中的一些方法来实现计算程序的时间效率和获得一定系统信息。
*/
public class Complex {
//用递归实现的Fibonacci数列的计算方法
public long fb(long n){
if(n==1||n==0){
return 1;
}else{
return fb(n-1)+fb(n-2);
}
}
public static void main(String args[]){
long start=System.currentTimeMillis();//开始计时
Complex c=new Complex();
c.fb(30);//计算 Fibonacci 数列,这个数列计算起来比较耗时,可以观察到时间的明显变化。
long end=System.currentTimeMillis();//计时结束。
long time=end-start;
System.out.println("计算长度为30的Fibonacci数列所用的时间:"+time);
System.out.print("所用操作系统的名称:"+System.getProperty("os.name")+"/n"+
"所用操作系统的版本号:"+System.getProperty("os.version")+"/n"+
"所用JDK的版本号:"+System.getProperty("java.version")+"/n"+
"JDK所在目录:"+System.getProperty("java.home")+"/n"+
"计算机的用户名:"+System.getProperty("user.name")+"/n"+
"计算机用户的工作目录:"+System.getProperty("user.home")+"/n"+
"Eclipse工作的目录:"+System.getProperty("user.dir"));
}
}
System类的可以干的事情有很多!
最新推荐文章于 2024-07-19 23:56:27 发布