-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreads.java
More file actions
77 lines (47 loc) · 1.08 KB
/
threads.java
File metadata and controls
77 lines (47 loc) · 1.08 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package class_programs;
import java.util.*;
class random implements Runnable{
public void run() {
Random rand= new Random();
try {
for(int i=0;i<10;i++) {
System.out.println(rand.nextInt(100)); //printing random numbers
Thread.sleep(1000);
}
}
catch(InterruptedException e) {
System.out.println("interruped "+ e);
}
}
}
class square implements Runnable{
int n;
square(int n){
this.n=n;
}
public void run() {
System.out.println("square of " + n + " is " + n*n);
}
}
class cube implements Runnable{
int n;
cube(int n){
this.n=n;
}
public void run() {
System.out.println("cube of "+ n + " is " + n*n*n);
}
}
public class threads {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("This program is written by\nAshik MR, 4NI19IS017, B section");
random robj = new random();
Thread t1 = new Thread(robj);
t1.start();
Thread t2 = new Thread(new square(10));
t2.start();
Thread t3 = new Thread(new cube(20));
t3.start();
}
}