program to implement FCFS algorithm in JAVA


import java.io.*;

class fcfs
{
public static void main(String[] arg) throws IOException
{
BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter number of processes");
int nop=Integer.parseInt(b.readLine());
int burst_time[] = new int[nop];
System.out.println("Enter burst time for each process");
for(int i =0;i burst_time[i]=Integer.parseInt(b.readLine());
int arrival_time[] = new int[nop];
System.out.println("Enter arrival time for each process");
for(int i=0;i arrival_time[i]=Integer.parseInt(b.readLine());
int wait_time[] = new int[nop];
System.out.println("Wait time for each process :");
System.out.println("Process 0 "+wait_time[0]+" units");
for(int i=1;i {
wait_time[i]=arrival_time[i-1]+burst_time[i-1]+wait_time[i-1]-arrival_time[i];
System.out.println("Process "+i+" "+wait_time[i]+" units");
}
}
}