You are on page 1of 2

DISK SCHEDULING: CSCAN

import java.io.*; public class CSCAN { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int a,b,c,d=1,i,hm=0,head,temp; int anarray[]=new int[30]; System.out.print("\n\n Program name: CSCAN Disk Scheduling\n"); System.out.print("\n\nEnter number of process: "); a=Integer.parseInt(br.readLine()); System.out.print("Initial Head Position: "); b=Integer.parseInt(br.readLine()); System.out.print("\n"); anarray[0]=0; for (c=1;c<=a;c++){ System.out.print("Request # "+d+": "); anarray[c]=Integer.parseInt(br.readLine()); d++; } anarray[c]=199; c++; anarray[c]=b; for (c=0;c<a+2;c++){ for (i=0;i<a+2-c;i++){ if (anarray[i]>anarray[i+1]){ temp=anarray[i]; anarray[i]=anarray[i+1]; anarray[i+1]=temp; } } } for (c=0;c<a+2;c++){ head=anarray[c]-anarray[c+1]; if (head<0){ head=head*(-1); } hm=hm+head; if(anarray[c]==b){ temp=anarray[c]-anarray[c-1]; hm=hm-temp; } } hm=hm+anarray[c]; System.out.println("\nTotal Head Movements: "+hm); } }

You might also like