Monday, March 24, 2014

Java program to print even and odd numbers using thread

class even extends Thread
{
public void run()
 {
  for(int i=1;i<=50;i++)
  {
   try
     {
        Thread.sleep(100);
        if(i%2==0)
        System.out.println(i);
      }
   catch(InterruptedException e)
     {
      System.out.println(e);
     }
    }
   }
}
class EvenThread
{
public static void main(String args[])
{
new even().start();
}
}

No comments:

Post a Comment