666666

666666 关注TA

666666

该文章投稿至Nemo社区   Java  板块 复制链接


其他类对象-Math-Runtime -System 类对象的使用

发布于 2016/04/20 21:18 1,305浏览 0回复 2,052

 其他类对象-Math类的使用:

package cn.itcast.p1.otherapi;
public class Mat {
public static void main(String[] args) {
// for (int i = 0; i < 10; i++) {
// int d = (int) (Math.random() * 10+1);
// int d=(int) Math.ceil(12.23);
// double d = Math.ceil(12.31);
// Double d=Math.floor(12.36);
// long d=Math.round(63.50);
double d=Math.pow(2, 3);
System.out.println(d);
}
}

其他类对象-Runtime类对象的使用:

package cn.itcast.p1.otherapi;
import java.io.IOException;
public class RuntimeDemo {
/**
* @param args
* @throws IOException
* @throws InterruptedException
*/
public static void main(String[] args) throws IOException, InterruptedException
{
/*
* Runtime:没有构造方法摘要,说明该类不可以创建对象。
* 又发现还有非静态的方法。说明该类应该提供静态的返回该类对象的方法。
* 而且只有一个,说明Runtime类使用了单例设计模式。
*
*/
Runtime r = Runtime.getRuntime();
// execute: 执行。 xxx.exe
Process p = r.exec("notepad.exe");
Thread.sleep(5000);
 193
p.destroy();
}
}

其他类对象-System类对象的使用:

package cn.itcast.p1.otherapi;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.Set;
public class SystemDemo {
private static final String LINE_SEPARATOR =
System.getProperty("line.separator");
/**
* @param args
*/
public static void main(String[] args) {
/*
* System:类中的方法和属性都是静态的。
* 常见方法:
* long currentTimeMillis();获取当前时间的毫秒值。
*/
// long l1 = 1335664696656l;//System.currentTimeMillis();
// System.out.println(l1/1000/60/60/24);//1335664696656
// code..
// long l2 = System.currentTimeMillis();
// System.out.println(l2-l1);
System.out.println("hello-"+LINE_SEPARATOR+" world");
// demo_1();
//给系统设置一些属性信息。这些信息是全局,其他程序都可以使用。
// System.setProperty("myclasspath", "c:\myclass");
}
public static void demo_1(){
//获取系统的属性信息,并存储到了Properties集合中。
/*
* properties集合中存储都是String类型的键和值。
* 最好使用它自己的存储和取出的方法来完成元素的操作。
*/

Properties prop = System.getProperties();
Set<String> nameSet = prop.stringPropertyNames();
for(String name : nameSet){
String value = prop.getProperty(name);
System.out.println(name+"::"+value);
}
}
}

点赞(0)
点了个评