-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrac6_2.java
56 lines (53 loc) · 1.13 KB
/
Prac6_2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.Random;
class Odd extends Thread{
int [] array; Odd(int [] array)
{
this.array=array; this.setName("Odd Thread: "); start();
}
public void run()
{
System.out.println(getName() + "\t");
for (int j=0;j<array.length;j++)
{
if(j%2==1)
{
System.out.println(getName()+" : "+array[j]);
}
}
}
}
class Even extends Thread
{
int [] array; Even(int [] array)
{
this.array=array; this.setName("Even Thread: "); start();
}
public void run()
{
System.out.println(getName() + "\t");
for (int j=0;j<array.length;j++)
{
if(j%2==0)
{
System.out.println(getName()+ " : "+ array[j]);
}
}
}
}
public class Prac6_2
{
public static void main(String[] args)
{
Random rand = new Random();
int arr[]= new int[15];
System.out.println("Random Numbers: ");
for (int j=0;j<arr.length;j++)
{
arr[j]=rand.nextInt(100);
System.out.println(arr[j]+" ");
}
Odd t1=new Odd(arr);
Even t2=new Even(arr);
System.out.println("\nJatan Bhimani\n 20CE007");
}
}