-
Notifications
You must be signed in to change notification settings - Fork 0
/
fcfs.java
56 lines (55 loc) · 1.2 KB
/
fcfs.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
import java.util.*;
public class fcfs
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.println("Enter the number of processes");
int p = s.nextInt();
int at[] = new int[p];
int bt[] = new int[p];
int ct[] = new int[p];
int tt[] = new int[p];
int wt[] = new int[p];
for(int i = 0;i < p;i++)
{
System.out.println("Enter the Arrival time");
at[i] = s.nextInt();
System.out.println("Enter the Burst time");
bt[i] = s.nextInt();
}
for(int i = 0;i < p;i++)
{
for(int j = 0;j < p-(i+1);j++)
{
if(at[j] > at[j+1])
{
int temp = at[j];
at[j] = at[j+1];
at[j+1] = temp;
temp = bt[j];
bt[j] = bt[j+1];
bt[j+1] = temp;
}
}
}
ct[0] = at[0] + bt[0];
for(int i = 1;i < p;i++)
{
if(at[i] > ct[i-1])
ct[i] = at[i] + bt[i];
else
ct[i] = ct[i-1] + bt[i];
}
for(int i = 0;i < p;i++)
{
tt[i] = ct[i] - at[i];
wt[i] = tt[i] - bt[i];
}
System.out.println("PR\tAT\tBT\tCT\tTT\tWT");
for(int i = 0;i < p;i++)
{
System.out.println(i + "\t" + at[i] + "\t" + bt[i] + "\t" + ct[i] + "\t" + tt[i] + "\t" + wt[i]);
}
}
}