-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathThreading.java
More file actions
60 lines (44 loc) · 1.22 KB
/
Copy pathThreading.java
File metadata and controls
60 lines (44 loc) · 1.22 KB
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
57
58
59
60
import java.util.*;
import java.util.Random;
class Square extends Thread{
int n;
public Square(int n){
this.n=n;
System.out.println("Square is : "+n*n);
}
}
class Cube extends Thread{
int n;
public Cube(int n){
this.n=n;
System.out.println("Cube is : "+n*n*n);
}
}
class Dummy extends Thread{
public void run(){
Random rand =new Random();
for(int i=0;i<10;i++){
int r= rand.nextInt(10);
System.out.println("Random num is :"+r);
if(r%2==0){
Square s= new Square (r);
s.start();
}
else{
Cube c= new Cube(r);
c.start();
}
try{
Thread.sleep(1000);
}
catch(InterruptedException ex){
System.out.println(ex);
}
}
}}
public class Threading{
public static void main(String[]args){
Dummy d= new Dummy();
d.start();
}
}