问个线程初级问题
这是我照着书上写的 可运行总是错误 不解 希望大家帮帮忙.....
class NewThread implements Runnable{
Thread t;
NewThread(){
//Create a new ,second thread
t=new Thread(this, "Demo Thread ");
System.out.println( "Child thread: "+t);
t.start();
}
public void run(){
try{
for(int i=5;i> 0;i--){
System.out.println( "Child Thread: "+i);
Thread.sleep(500);
}
}catch (InterruptedException e){
System.out.println( "Child interrupted. ");
}
}System.out.println( "Exiting child thread. ");
}
public class Thread {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new NewThread();
try{
for(int i=5;i> 0;i--){
System.out.println( "Main Thread: "+i);
Thread.sleep(1000);
}
}catch(InterruptedException e){
System.out.println( "Main thread interrupted. ");
}
System.out.println( "Main thread exiting. ");
}
}
还有一个是copy论坛上的 可还是错
String s= " ";
int n=0;
try{
BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
System.out.println( "input a number: ");
s=in.readLine();//r 小写
n=Integer.parseInt(s);//不好意思,上面写错了 parseInt中i大写
}
catch(
IOException e) {}
System.out.println( "you input a "+n);
说BufferedReader cannot be resolved to a type
希望大家指点一下 我在EC下 新手...
------解决方案--------------------第1个程序 System.out.println( "Exiting child thread. "); 这句放错地方了,请放在方法里面