Skip to main content

Posts

Showing posts from March 12, 2014

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"); f