-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfirstcome.java
More file actions
56 lines (49 loc) · 1.76 KB
/
firstcome.java
File metadata and controls
56 lines (49 loc) · 1.76 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
// first come first serve
import java.io.*;
class Fcfs
{
public static void main(String args[]) throws Exception
{
int n,AT[],BT[],WT[],CT[];
float AVG=0;
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println( "Number Of Process" );
n=Integer.parseInt(br.readLine());
BT=new int[n];
WT=new int[n];
CT=new int[n];
AT=new int[n];
System.out.println( "Enter Burst Time For Each process\n______________________________");
for(int i=0;i<n;i++)
{
System.out.println( "Burst Time For Process " +(i+1));
BT[i]=Integer.parseInt(br.readLine());
}
System.out.println( "______________________________" );
for(int i=0;i<n;i++)
{
System.out.println( "Arrival Time For Process" +i );
AT[i]=Integer.parseInt(br.readLine());
}
System.out.println( "______________________________" );
WT[0]=0;
for(int i=1; i<n; i++)
{
WT[i]=WT[i-1]+BT[i-1];
WT[i]=WT[i]-AT[i];
}
for(int i=0; i<n; i++)
{
CT[i]=WT[i]+BT[i];
AVG=AVG+WT[i];
}
System.out.println(" Process BT WT TotalTime ");
for(int i=0; i<n; i++)
{
System.out.println(" "+ i + " "+BT[i]+" "+WT[i]+" "+CT[i]);}
AVG=AVG/n;
System.out.println("___________________________________________");
System.out.println("Average Waiting Time="+AVG+" \n___________________________________________");
}
}