import java.util.*;
class MaximumElement extends Thread{
int dt[];
int a,b;
public MaximumElement(int f[],int a, int b){
dt = f;
this.a = a;
this.b = b;
}
public void run(){
for(int i = a; i < b ; i++){
int j = i; int k = i+1;
while(k<b){
if (dt[j] < dt[k])
j= k ;
else
;
k++;
}
int temp = dt[i]; dt[i] = dt[j]; dt[j] = temp;
}
}
public int getMax(){
return dt[a];
}
}
class Q2{
public static void main(String args[]){
int f[] = new int[1000];
Random r = new Random();
for(int j = 0; j < f.length;j++)
f[j]=r.nextInt(1000);
MaximumElement t1 = new MaximumElement(f,0,500);
MaximumElement t2 = new MaximumElement(f,500,1000);
t1.start();
t2.start();
try{
t1.join();
t2.join();
}catch(InterruptedException e){
}
for(int i = 0 ; i < f.length; i++){
if(i==50)
System.out.println();
System.out.println(f[i]+"");
}
System.out.println("Max number in t1 is"+t1.getMax());
System.out.println("Max number in t2 is"+t2.getMax());
if(t1.getMax() >= t2.getMax())
System.out.println(t1.getMax());
}
}