-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmul.java
More file actions
62 lines (57 loc) · 1.26 KB
/
mul.java
File metadata and controls
62 lines (57 loc) · 1.26 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
/*
Write a Java program that implements a multithreaded application that has three threads.
First thread generates a random integer for every 1 second;
second thread computes the square of the number and prints;
third thread will print the value the cube of the number.
*/
package Multithread_Application;
import java.util.*;
class Square extends Thread{
private int num;
Square(int n){
num = n;
}
public void printSquare() {
System.out.println("Square of "+ num +" is "+ (num * num));
}
public void run() {
printSquare();
}
}
class Cube extends Thread{
private int num;
Cube(int n){
num = n;
}
public void printCube() {
System.out.println("Cube of "+ num +" is "+ (num * num * num));
}
public void run() {
printCube();
}
}
class RandInt extends Thread{
public void printRandom() throws InterruptedException {
Random rd = new Random();
while(true) {
int rnum = rd.nextInt(10);
System.out.println("Random Number is"+ rnum);
Thread.sleep(3000);
Square s = new Square(rnum);
Cube c = new Cube(rnum);
s.start();
c.start();
}
}
public void run() {
try {
printRandom();
}catch(InterruptedException e) {}
}
}
public class mul {
public static void main(String[] args) {
RandInt ob1 = new RandInt();
ob1.start();
}
}