多线程课后作业
2016-03-15 16:48
351 查看
P364--1
尝试定义一个继承Thread类的类,并覆盖run()方法,在run()方法中每隔100毫秒打印一句话
View Code
尝试定义一个继承Thread类的类,并覆盖run()方法,在run()方法中每隔100毫秒打印一句话
package org.hanqi.zwxx; public class TestThread extends Thread { public void run() { int i=0; while(true) { if(i<9) { System.out.print("这是第0"+(i+1)+"句话\t"); } else { System.out.print("这是第"+(i+1)+"句话\t"); } i++; try { Thread.sleep(100); //100毫秒输出一个 } catch (InterruptedException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } if(i%5==0) //每5个换行 { System.out.println("\n"); } } } public static void main(String[] args) { TestThread t=new TestThread(); t.start(); } }
View Code
相关文章推荐
- 【OA外勤签到】软件免费下载
- ImageView的属性及使用相关
- Nginx配置文件nginx.conf中文详解
- Java之Servlet编程实例一
- python2.7配置matplotlib
- Redux API之creatStore
- 让DIV水平垂直居中的两种完美方法推荐
- JVM 类加载器介绍及其双亲委托机制
- 网页层叠样式表(css+html)
- finish with non-zero exit value 42
- 十六进制转二进制转八进制
- 个人分析
- 【Unity3D】【NGUI】怎样动态给EventDelegate加入參数
- 20 Valid Parentheses
- Oracle存在则修改,不存在插入记录
- 泛型数据容器Demo
- 关于maven下载jar包失败的问题的总结和解决
- Modernizr——为HTML5和CSS3而生!
- DB2获取月份第一天最后一天
- 关于AssetBundle、热更新、BestHttp