1 Star 0 Fork 0

小春/OnlinePythonTutor

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Rolex.java 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
Philip Guo 提交于 2015-02-11 06:13 +08:00 . moar
public class Rolex {
private final long start;
public Rolex() {
start = System.currentTimeMillis();
}
// return time (in seconds) since this object was created
public double elapsedTime() {
long now = System.currentTimeMillis();
return (now - start) / 1000.0;
}
public static void main(String[] args) {
Rolex watchOne = new Rolex();
// waste time so it is large enough to be measurable
try {Thread.sleep(500);} catch (InterruptedException e) {}
Rolex watchTwo = new Rolex();
// waste time so it is large enough to be measurable
try {Thread.sleep(500);} catch (InterruptedException e) {}
// right now, watchOne is older
System.out.println("watchOne " + watchOne.elapsedTime());
System.out.println("watchTwo " + watchTwo.elapsedTime());
Rolex watchTmp = watchOne;
watchOne = watchTwo;
watchTwo = watchTmp;
// swapped! now watchTwo is the older one
// e.g. watchTwo.elapsedTime() returns a value
// (slightly) larger than watchOne.elapsedTime()
System.out.println("watchOne " + watchOne.elapsedTime());
System.out.println("watchTwo " + watchTwo.elapsedTime());
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wython/OnlinePythonTutor.git
git@gitee.com:wython/OnlinePythonTutor.git
wython
OnlinePythonTutor
OnlinePythonTutor
master

搜索帮助