题目如下:
创建线程,输出数字1到100,在每个数字输出之间相隔1秒,用sleep()方法实现,并遵循如下要求:
1、用实现Runnable接口方式创建一个线程t。
2、重写run()方法,用于输出数字的代码位于其中。
3、每输出10个数字以后,输出一个字符串“已经完成10个数字。”
4、long型数字表示毫秒。我编写的代码如下:
public class TestThread{
public static void mian(String [] args){
Thread thread=new Thread(new Runnable(){
public void run() {
for ( int i = 1; i <= 100; i++) {
if (i%10 == 0){
System.out.println("已经完成10个数字!");
}
try{
Thread.sleep(1000);
System.out.println(i);
}catch(InterruptedException e){
System.out.println(" InterruptedException ");
}
}
}
});
thread.start();
}
}
请帮忙在我的基础上改动!!谢谢~~
创建线程,输出数字1到100,在每个数字输出之间相隔1秒,用sleep()方法实现,并遵循如下要求:
1、用实现Runnable接口方式创建一个线程t。
2、重写run()方法,用于输出数字的代码位于其中。
3、每输出10个数字以后,输出一个字符串“已经完成10个数字。”
4、long型数字表示毫秒。我编写的代码如下:
public class TestThread{
public static void mian(String [] args){
Thread thread=new Thread(new Runnable(){
public void run() {
for ( int i = 1; i <= 100; i++) {
if (i%10 == 0){
System.out.println("已经完成10个数字!");
}
try{
Thread.sleep(1000);
System.out.println(i);
}catch(InterruptedException e){
System.out.println(" InterruptedException ");
}
}
}
});
thread.start();
}
}
请帮忙在我的基础上改动!!谢谢~~
解决方案 »
- jxl读excel文件出错,jxl.read.biff.BiffException: Unable to recognize OLE stream
- JAVA是什么?
- 怎么判断一个线程是不是正常终止的
- J关于AVA输入流的问题
- 我在文本框中输入"0.4,0.18,0.1,0.1,0.07,0.06,0.05,0.04",想让 double weight[]={0.4,0.18,0.1,0.1,0.07,0.06,0.05,0.04};
- java 控制声音问题
- JBuilder2006中生成exe文件的问题
- 求教!!!
- java怎样向c客户端发送数据
- 怎么设计jar包,并暴露接口给其他人调用,求具体实现思路!
- 进制转换的问题
- 为什么中文读出来是乱码?
public class T {
public static void main(String[] args) {
Thread thread = new Thread(new Runnable() {
public void run() {
for (int i = 1; i <= 100; i++) {
try {
Thread.sleep(1000);
System.out.println(i);
if (i % 10 == 0) {
System.out.println("已经完成10个数字!");
}
} catch (InterruptedException e) {
System.out.println(" InterruptedException ");
}
}
}
});
thread.start();
}
}
mian是啥东西来着………………