import java.io.*;
import java.util.*;
public class ThreadTest implements Runnable{
int sleeptime;
int count;
int num;
public ThreadTest(int time, int timez){
int sleeptime = time;
int count = timez;
int num = 0;
}
public void run(){
System.out.println("Thread is running!");
while(num < count){
count++;
System.out.println(new Date(System.currentTimeMillis()));
Thread.sleep(sleeptime);
}
}
public void stop(){
System.out.println("Thread is dead!");
}
public static void main(String[] args){
ThreadTest tt = new ThreadTest(100,20);
tt.start();
}
}
//找不到符号
import java.util.*;
public class ThreadTest implements Runnable{
int sleeptime;
int count;
int num;
public ThreadTest(int time, int timez){
int sleeptime = time;
int count = timez;
int num = 0;
}
public void run(){
System.out.println("Thread is running!");
while(num < count){
count++;
System.out.println(new Date(System.currentTimeMillis()));
Thread.sleep(sleeptime);
}
}
public void stop(){
System.out.println("Thread is dead!");
}
public static void main(String[] args){
ThreadTest tt = new ThreadTest(100,20);
tt.start();
}
}
//找不到符号
解决方案 »
- 谁能为我讲清楚编译,装载,连接,初始化这之间的关系和顺序?越清楚越好。
- 构造器的初始化顺序问题(这代码为什么这样)
- 又来求帮助了。。这个好像是树遍历? 求高手找规律
- 呼叫bigbug9002 大哥,,请进入
- 关于JAVA中的I/O流
- 想开始学JAVA,看到两本书,不知选那本.请各位谈谈
- 调用Frame的dispose方法后再new Frame的问题
- 那位朋友能否详细讲一下上溯造型?
- Java中在线程中再开线程,可以么?
- 初学Java时,do-while应该怎样写
- 请...高...人...指...教 如何理解 public <T> T ifThenElse(boolean b, T first, T second) 中 <T> 的语法含义
- 一个小小的问题 想不明白 望大侠指点迷津
Thread ttt=new Thread(tt);
ttt.start();
System.out.println("Thread is running!");
while (num < count) {
count++;
System.out.println(new Date(System.currentTimeMillis()));
try {Thread.sleep(sleeptime);
} catch(Exception ex){
System.out.println(ex);
}
}
}还有一个错误 加上异常处理
sleeptime = time;
count = timez;
num = 0;
}要这样写啊
不然 循环永远运行不了
import java.util.*;public class ThreadTest implements Runnable{
int sleeptime;
int count;
int num;
public ThreadTest(int time, int timez){
sleeptime = time; //修改处
count = timez; //修改处
num = 0; //修改处
}
public void run(){
System.out.println("Thread is running!");
while(num < count){
num++; //修改处
System.out.println(new Date(System.currentTimeMillis()));
try{
Thread.sleep(sleeptime);}//修改处
catch(Exception e){};
}
stop();//修改处
}
public void stop(){
System.out.println("Thread is dead!");
}
public static void main(String[] args){
ThreadTest tt = new ThreadTest(100,20);
Thread ttt=new Thread(tt); //修改处
ttt.start(); //修改处
}
}楼主程序有逻辑错误 呀 已经修改好 请仔细看
按zhonglizhi(111)的改法 还是有错误!
无法访问Thread line 19