Skip to main content

Merging two string array with the use of threads

import java.io.*;
import java.lang.*;

class M3 extends Thread
{
String c[]=new String[10],t;
int i,j;
M3(M1 a,M2 b)
     {
for(i=0;i<a.a.length;i++)
c[i]=a.a[i];
for(i=0;i<b.a.length;i++)
c[5+i]=b.a[i];
    }
public void run()
   {

for(i=0;i<9;i++)
{
for(j=0;j<8;j++)
{
if(c[j].compareTo(c[j+1])>0)
{
t=c[j];
c[j]=c[j+1];
c[j+1]=t;
}}}
System.out.println("\nThe full list");
for(i=0;i<10;i++)
 System.out.println(c[i]);
    }


}

class M1 extends Thread
{
int i;
String a[]=new String[5];

public void run()
{
try
{
DataInputStream dd= new DataInputStream(System.in);
System.out.println("Enter  for thread1");
for(i=0;i<5;i++)
for(i=0;i<5;i++)
{
a[i]=dd.readLine();

}
}
catch(Exception e) {}


}

}


class M2 extends Thread
{
int i;
String a[]=new String[5];

public void run()
{
try
{
DataInputStream dd= new DataInputStream(System.in);
System.out.println("Enter  for thread2");
for(i=0;i<5;i++)
{
a[i]=dd.readLine();
}
}
catch(Exception e) {}
}



}




public class Use2


{
public static void main(String args[])
{


M1 t1 = new M1();
M2 t2 = new M2();

t1.start();
try
{
t1.join();
}
catch(Exception e) {}

t2.start();

try
{
t2.join();

}
catch(Exception e) {}
M3 t3 = new M3(t1,t2);
t3.start();
}
}

Comments

Popular posts from this blog

unix commands