-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFcfs.java
More file actions
57 lines (48 loc) · 1.52 KB
/
Fcfs.java
File metadata and controls
57 lines (48 loc) · 1.52 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
import java.util.*;
import java.lang.*;
class Fcfs
{
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int pid[] = new int[50];
int bt[] = new int[50];
int n;
System.out.println("Enter the number of process :");
n = sc.nextInt();
System.out.println("Enter process id of all the process :");
for(int i=0;i<n;i++)
{
pid[i] = sc.nextInt();
}
System.out.println("Enter burst time of all the process :");
for(int i=0;i<n;i++)
{
bt[i] = sc.nextInt();
}
int i;
int wt[] = new int[n];
wt[0] = 0;
for(i=1;i<n;i++)
{
wt[i]=(bt[i-1]+wt[i-1]);
}
System.out.println("Process ID Burst Time Waiting Time Turnaround Time");
float twt = 0.0f;
float tat = 0.0f;
for(i=0;i<n;i++)
{
System.out.println(pid[i] + "\t\t" + bt[i] + "\t\t" + wt[i] + "\t\t" + bt[i]+wt[i] + "\t\t");
//System.out.println(bt[i] + "\t\t");
//System.out.println(wt[i] + "\t\t");
//System.out.println(bt[i]+wt[i] + "\t\t");
twt += wt[i];
tat += wt[i] + bt[i];
}
float att , awt;
awt = twt/n;
att = tat/n;
System.out.println("Average waiting Time is " + awt);
System.out.println("Average Turnaround Time is " + att);
sc.close();
}
}