-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiple.java
109 lines (62 loc) · 1.16 KB
/
Multiple.java
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import java.util.*;
class Multiple implements Runnable
{
int n;
public Multiple(int n)
{
this.n = n;
}
public void run()
{
for(int i =1 ;i<=n;i++ )
{ if(i==(int)(n/2))
{
try { Thread.sleep(1000);
}
catch(Exception e)
{}
}
int c; c=Multiple(n,i); if(c==0)
System.out.println(n+" is divisible by "+i);
}
}
public int Multiple(int n,int i)
{
if(n%i==0) return 0; else return 1;
}
}
class Fact implements Runnable
{
int n;
public Fact(int n)
{
this.n = n;
}
public void run() {
for(int i =1 ;i<=n;i++ )
{
System.out.println("Factorial : "+i+"! = "+fact(i)); try {
Thread.sleep(1000);
}
catch(Exception e)
{
}
}
}
public int fact(int n)
{
if(n==1) return 1;
else return(fact(n-1)*n);
}
}
class multiThread
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in); System.out.println("Enter the number:");
Thread T1 = new Thread(new Multiple(sc.nextInt()));
System.out.println("Enter the number terms upto which Factorial is required"); Thread T2 = new Thread(new Fact(sc.nextInt()));
T1.start();
T2.start();
}
}