-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomThread.java
More file actions
37 lines (37 loc) · 806 Bytes
/
RandomThread.java
File metadata and controls
37 lines (37 loc) · 806 Bytes
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
import java.util.*;
class Odd extends Thread{
private int num;
Odd(int num){
this.num=num;
}
public void run(){
System.out.println("Cube of "+num+" = "+num*num*num);
}
}
class Even extends Thread{
private int num;
Even(int num){
this.num=num;
}
public void run(){
System.out.println("Square of "+num+" = "+num*num);
}
}
public class RandomThread extends Thread
{
Random r=new Random();
public void run(){
for(int i=0;i<10;i++){
int num=r.nextInt(100);
if(num%2==0){
new Even(num).start();
}
else{
new Odd(num).start();
}
}
}
public static void main(String[] args) {
new RandomThread().start();
}
}