|
| 1 | +/** |
| 2 | + * |
| 3 | + */ |
| 4 | +package Q1; |
| 5 | + |
| 6 | +import java.util.Arrays; |
| 7 | +import java.util.Scanner; |
| 8 | + |
| 9 | +/** |
| 10 | + * @author M.NAVEEN |
| 11 | + * RANDOM CODER'S |
| 12 | + * Tech/Project Lead Android Club |
| 13 | + */ |
| 14 | +public class ThreadDemo |
| 15 | +{ static Scanner nav=new Scanner(System.in); |
| 16 | + public static void main(String...strings) throws InterruptedException |
| 17 | + { int x[]; |
| 18 | + |
| 19 | + System.out.println("Enter the Size of x :n"); |
| 20 | + x=new int[nav.nextInt()]; |
| 21 | + System.out.println("Enter the elements in x Array"); |
| 22 | + for(int i=0;i<x.length;i++) |
| 23 | + { |
| 24 | + x[i]=nav.nextInt(); |
| 25 | + } |
| 26 | + A t1=new A(); |
| 27 | + B t2=new B(); |
| 28 | + t1.start(); |
| 29 | + t2.start(); |
| 30 | + t1.join(); |
| 31 | + t2.join(); |
| 32 | + int temp[] =t1.merge(x); |
| 33 | + t2.printing(temp); |
| 34 | + |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | + |
| 39 | +class A extends Thread{ |
| 40 | + int y[]; |
| 41 | + Scanner nav=new Scanner(System |
| 42 | + .in); |
| 43 | + @Override |
| 44 | + public void run() |
| 45 | + { |
| 46 | + System.out.println("Enter the Size of Y :M :"); |
| 47 | + |
| 48 | + y=new int[nav.nextInt()]; |
| 49 | + System.out.println("Enter the Element of y"); |
| 50 | + for(int i=0;i<y.length;i++) |
| 51 | + { |
| 52 | + y[i]=nav.nextInt(); |
| 53 | + } |
| 54 | + System.out.println(Thread.currentThread().getName()); |
| 55 | + } |
| 56 | + |
| 57 | + synchronized int [] merge(int x[]) |
| 58 | + { |
| 59 | + int temp[]=new int[x.length+y.length]; |
| 60 | + int i; |
| 61 | + for(i=0;i<x.length;i++) |
| 62 | + { |
| 63 | + temp[i]=x[i]; |
| 64 | + } |
| 65 | + for(int j=0;j<y.length;j++) |
| 66 | + { |
| 67 | + temp[i+j]=y[j]; |
| 68 | + } |
| 69 | + return temp; |
| 70 | + } |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +} |
| 75 | + |
| 76 | +class B extends Thread { |
| 77 | + |
| 78 | + synchronized void printing(int merge[]) |
| 79 | + { System.out.println("Element is Array After removing Even Number :"); |
| 80 | + for(int i=0;i<merge.length;i++) |
| 81 | + { |
| 82 | + if( merge[i]%2!=0) {System.out.print(merge[i]+" ");} |
| 83 | + } |
| 84 | + System.out.println(); |
| 85 | + System.out.println(Thread.currentThread().getName()); |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public void run() { |
| 90 | + |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | + |
0 commit comments