-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMultiThreading.java
More file actions
60 lines (52 loc) · 1.55 KB
/
Copy pathMultiThreading.java
File metadata and controls
60 lines (52 loc) · 1.55 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
package com.programs;
import java.util.Random;
import java.util.Scanner;
class Runnable1 implements Runnable {
public void run() {
Scanner in = new Scanner(System.in);
System.out.println("Enter the number to find square:");
int a = in.nextInt();
int b = a*a;
System.out.println("The sqaure is:"+b);
}
}
class Runnable2 implements Runnable {
public void run() {
Scanner in = new Scanner(System.in);
System.out.println("Enter the number to find cube:");
int a = in.nextInt();
int d = a*a*a;
System.out.println("The cube is:"+d);
}
}
class Runnable3 implements Runnable {
public void run() {
int n,i;
Scanner in = new Scanner(System.in);
Random rand = new Random();
n = rand.nextInt(50);
System.out.println("Enter the number of elements:");
n = in.nextInt();
int arr[] = new int[n];
for(i=0;i<n;i++)
arr[i] = rand.nextInt(50);
System.out.println("The random elements are:");
for(i=0;i<n;i++)
System.out.println(arr[i]);
}
}
public class MultiThreading {
public static void main(String[] args) throws InterruptedException {
Runnable r1 = new Runnable1();
Thread t1 = new Thread(r1);
t1.start();
Thread.sleep(5000);
Runnable r2 = new Runnable2();
Thread t2 = new Thread(r2);
t2.start();
Thread.sleep(5000);
Runnable r3 = new Runnable3();
Thread t3 = new Thread(r3);
t3.start();
}
}