You are on page 1of 2

DISK SCHEDULING FCFS

import java.io.*; public class FCFS { public static void main(String[]args) throws IOException { BufferedReader br=new BufferedReader (new InputStreamReader(System.in)); int a,c,x=2,y=3,thm=0,rw,r,t; int array[]=new int [30]; int anarray[]=new int [30]; System.out.print("\n\n Program Name: FCFS (Disk Scheduling)");

System.out.print("\n\nNumber of Process: "); a=Integer.parseInt(br.readLine()); System.out.print("Initial Head Movement: "); rw=Integer.parseInt(br.readLine()); System.out.print("\n"); for(c=0;c<a;c++) { t=c+1; System.out.print("Request Queue " +t+ ": "); array[c]=Integer.parseInt(br.readLine()); } for(c=0;c<a-1;c++) { anarray[c]=array[c]-array[c+1]; if (anarray[c]<0) { anarray[c]=anarray[c]*-1; } } for(c=0;c<a-1;c++) { thm=thm+anarray[c]; } r=array[0]-rw; if (r<0) { r=r*-1; } thm=thm+r; System.out.println("\nTotal Head Movement: "+thm); }

You might also like