daily pastebin goal
80%
SHARE
TWEET

Untitled

a guest May 17th, 2018 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package sjn;
  2. import java.util.Scanner;
  3. public class SJN {
  4. public static void main(String args[]){
  5. int burst_time[],process[],waiting_time[],tat[],i,j,n,total=0,pos,temp;
  6. float wait_avg,TAT_avg;
  7. Scanner s = new Scanner(System.in);
  8.  
  9. System.out.print("Enter number of process: ");
  10. n = s.nextInt();
  11.  
  12. process = new int[n];
  13. burst_time = new int[n];
  14. waiting_time = new int[n];
  15. tat = new int[n];
  16.  
  17. System.out.println("\nEnter Burst time:");
  18. for(i=0;i<n;i++)
  19. {
  20. System.out.print("\nProcess["+(i+1)+"]: ");
  21. burst_time[i] = s.nextInt();;
  22. process[i]=i+1; //Process Number
  23. }
  24.  
  25. //Sorting
  26. for(i=0;i<n;i++)
  27. {
  28. pos=i;
  29. for(j=i+1;j<n;j++)
  30.     {
  31.     if(burst_time[j]<burst_time[pos])
  32.     pos=j;
  33.     }
  34.  
  35.     temp=burst_time[i];
  36.     burst_time[i]=burst_time[pos];
  37.     burst_time[pos]=temp;
  38.  
  39.     temp=process[i];
  40.     process[i]=process[pos];
  41.     process[pos]=temp;
  42.     }
  43.  
  44.  
  45.  
  46.     //First process has 0 waiting time
  47.     waiting_time[0]=0;
  48.     //calculate waiting time
  49.     for(i=1;i<n;i++) {
  50.     waiting_time[i]=0;
  51.     for(j=0;j<i;j++)
  52.     waiting_time[i]+=burst_time[j];
  53.     total+=waiting_time[i];
  54.     }
  55.  
  56.  
  57.     //Calculating Average waiting time
  58.     wait_avg=(float)total/n;
  59.     total=0;
  60.  
  61.     System.out.println("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time");
  62.     for(i=0;i<n;i++) {
  63.     tat[i]=burst_time[i]+waiting_time[i]; //Calculating Turnaround Time
  64.     total+=tat[i];
  65.     System.out.println("\n p"+process[i]+"\t\t "+burst_time[i]+"\t\t "+waiting_time[i]+"\t\t "+tat[i]);
  66.     }
  67.  
  68.     //Calculation of Average Turnaround Time
  69.     TAT_avg=(float)total/n;
  70.     System.out.println("\n\nAverage Waiting Time: "+wait_avg);
  71.     System.out.println("\nAverage Turnaround Time: "+TAT_avg);
  72.  
  73.     }    
  74. }
RAW Paste Data
Top