Skip to main content

Creating Threads and Each Thread Displaying a Simple Message

class MyThreada extends Thread
{
 public void run()
 {
  while(true)
  {
   try
   {
    System.out.println("Good Morning");
    sleep(1000); 
   }
   catch (InterruptedException e)
   {
   }
  }
 }
}
class MyThreadb extends Thread
{
 public void run()
 {
  while(true)
  {
   try
   {
    System.out.println("Hello");
    sleep(2000);
   }
   catch (InterruptedException e)
   {
   }
  }
 }
}
class MyThreadc extends Thread
{
 public void run()
 {
  while(true)
  {
   try
   {
    System.out.println("Welcome");
    sleep(3000);
   }
   catch (InterruptedException e)
   {
   }
  }
 }
}
class MyThreadMain 
{
 public static void main(String[] args) 
 {
  MyThreada a=new MyThreada();
  MyThreadb b=new MyThreadb();
  MyThreadc c=new MyThreadc();
  a.start();
  b.start();
  c.start();
 }
}

Comments

Popular posts from this blog

Find Value of S=ut+1/2*a*t**2.

PROCEDURE:-        1.enter values for u,a,t to find distance        2.find distance with the formulae ut+1/2at 2        3.print the above result CODE:- #include<stdio.h> #include<conio.h> void main() {   float u,t,a,S;   clrscr();   printf(“enter values u,t,a”);   scanf(“%f %f %f”, &u,&t,&a);   S=(u*t)+(0.5*a*t*t);   printf(“\n  S = %f”, S); } Input:- enter values u,t,a               U=10,t=4,a=4.9 Output:- S =79.200