云谷子:或许可以这样:
class Counter extends Thread{
@Override
public void run() {
try {
int sum=0;
for(int i=1;i<=10;i++){
sleep(1000);
sum+=i;
System.out.println("sum="+sum);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
//print
class Printer extends Thread{
@Override
public void run() {
try {
for(int i=1;i<=10;i++){
sleep(1100);
System.out.println("print Here");
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public class HelloWorld {
public static void main(String[] args) {
Counter c=new Counter();
Printer p=new Printer();
c.start();
p.start();
System.out.println("main eend..");
}
}
0 点赞 评论 收藏
分享
2015-12-30 21:57
宿州学院 Java zhisheng_blog:https://segmentfault.com/a/1190000002683782
浅谈 Java
字符串(String, StringBuffer, StringBuilder)
0 点赞 评论 收藏
分享
关注他的用户也关注了: