470,862 Members | 1,835 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,862 developers. It's quick & easy.

Exception in Thread error

While I was studying from the book, I copy this program and try to compile
and did not work.
Please help

/* It start here **/
import java.lang.*;

public class CountDown implements Runnable
{
static int cycles = 10 ;
public static void main(String[] args )
{
int mx = Integer.parseInt( args[0] ) ;

for( int n = 0 ; n < mx ; n++ )
{
Runnable cdown = new CountDown( n );
Thread t = new Thread( cdown );
t.start();
}
}

int myNum ;
CountDown( int n )
{
myNum = n ;
}

public void run()
{
for( int i = cycles ; i >= 0 ; i-- )
{
System.out.println( myNum + " = " + i );

try
{
Thread.sleep( 1000 );
}

catch(InterruptedException e)
{
}
}
}
} // end of the CountDown class

/* end **/

Jul 17 '05 #1
1 1587
yu859sem wrote:
While I was studying from the book, I copy this program and try to compile
and did not work.
Please help

/* It start here **/
import java.lang.*;

public class CountDown implements Runnable
{
static int cycles = 10 ;
public static void main(String[] args )
{
int mx = Integer.parseInt( args[0] ) ;

for( int n = 0 ; n < mx ; n++ )
{
Runnable cdown = new CountDown( n );
Thread t = new Thread( cdown );
t.start();
}
}

int myNum ;
CountDown( int n )
{
myNum = n ;
}

public void run()
{
for( int i = cycles ; i >= 0 ; i-- )
{
System.out.println( myNum + " = " + i );

try
{
Thread.sleep( 1000 );
}

catch(InterruptedException e)
{
}
}
}
} // end of the CountDown class

/* end **/

The program is fine. Just think about where the program gets it's *mx
value* .. Look at the following statement!

int mx = Integer.parseInt( *args[0]* )

--
Thanks in Advance...
IchBin
__________________________________________________ ________________________

'Laughter is inner jogging'
- Norman Cousins, editor and author (1915-1990)
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Bhavya Shah | last post: by
44 posts views Thread by craig | last post: by
2 posts views Thread by akameswaran | last post: by
6 posts views Thread by Steve | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.