本人刚学java 不久,在验证多线程如何在同一程序中运行时,此程序不知哪里出了问题,请高手帮忙看看!谢谢你们得指点迷津!
class Sister extends Thread{
 public Sister(String str){
   super(str);  
   

 public void run(){
for(int i=0;i<6;i++)
{
System.out.println(getName()+"is running:"+i);
try{sleep((int)(Math.random()*1000));}
    catch(InterruptedException e){}

}

}
 System.out.println(getName()+"is running:"+i);
 }


 
 class CountingThread {
public static void main(String []args){
System.out.println("the siters Janny and Marry are counting the threads");
System.out.println("who are the first to runnig?");
new Sister("Janny").start();
new Sister("Marry").start();
}

}

解决方案 »

  1.   

    System.out.println(getName()+"is running:"+i);
    ==============================================
    没在方法里边吧
      

  2.   

    "System.out.println(getName()+"is running:"+i);"怎么是个孤儿啊,而且这个i从那里读的到啊??
      

  3.   

    可是编译得时候,出错信息是cant find main class 怎么回事呢?
      

  4.   

    javac 文件名.java
    java  CountingThread
      

  5.   

    我不在DOS下编译,我用的是Eclipse
      

  6.   

    class CountingThread 前面加个public就没有cant find main class问题了
      

  7.   

    是你工具没用明白
    你把这个文件在DOS里面去运行试一下 
    我的都好使
      

  8.   

    楼主在开玩笑哦在DOS里根本就编译不通过,出现下面错误!CountingThread.java:16: <identifier> expected
     System.out.println(getName()+"is running:"+i);
                       ^
    1 error
    你的第二个System语句就没有放在方法内部!
      

  9.   


    class Sister extends Thread {
    public Sister(String str) {
    super(str); } public void run() {
    for (int i = 0; i < 6; i++) {
    System.out.println(getName() + "is running:" + i);
    try {
    sleep((int) (Math.random() * 1000));
    } catch (InterruptedException e) {
    } System.out.println(getName() + "is running:" + i);
    } }
    }public class CountingThread {
    public static void main(String[] args) {
    System.out
    .println("the siters Janny and Marry are counting the threads");
    System.out.println("who are the first to runnig?");
    new Sister("Janny").start();
    new Sister("Marry").start();
    }}
      

  10.   

    ------------------------------------
    ohuan(orckerth) ( ) 信誉:100 
    -------------------------------------
    正解还有保存的.java文件名要和包含main()方法的那个类的类名相同
      

  11.   

    (String []args) ????????????
      

  12.   

    你写错了2个地方 
    第一个错:
    }
     System.out.println(getName()+"is running:"+i);
     }
    这里的这句代码不能放在类里面 只能放在类里的一个方法中.第二个错:
     class CountingThread {
    public static void main(String []args){
    包含 main方法的类,要放在一个声明为public而且和文件名相同的类当中.
    以上两个地方就你的错误了~~