-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfcfs.java
More file actions
33 lines (26 loc) · 692 Bytes
/
fcfs.java
File metadata and controls
33 lines (26 loc) · 692 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
import java.util.*;
class fcfs
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter no. of processes");
int n = sc.nextInt();
System.out.println("Enter n disk access points");
int a[] = new int[n];
for(int i=0;i<n;i++)
a[i] = sc.nextInt();
System.out.println("Enter head");
int head = sc.nextInt();
int time = 0;
int curr = head;
for(int i=0;i<n;i++)
{
int retrieve = a[i];
System.out.println("Step "+(i+1)+" Current pointer is "+retrieve);
time = time + Math.abs(retrieve-curr);
curr = retrieve;
}
System.out.println("Average seeking time is "+(time/n));
}
}