Posts

Showing posts from January, 2017

Priority Scheduling Program in Java

Image
Program: import java.util.Scanner; class priority_sch  int pos=0,temp; {  public static void main(String args[])  {   Scanner sc=new Scanner(System.in);  System.out.println("Enter the number of processes:");   int n=sc.nextInt();  int i;  System.out.println("Enter the burst times:");  int p[]=new int[n];  int bt[]=new int[n];  int pt[]=new int[n];  int wt[]=new int[n];  int tat[]=new int[n];  for(i=0;i<n;i++)  {p[i]=i+1;   bt[i]=sc.nextInt();  }  System.out.println("Enter priority time:");  for(i=0;i<n;i++)   pt[i]=sc.nextInt(); for(i=0;i<n;i++){pos=i;   for(int j=i+1;j<n;j++)    {     if(pt[j]<pt[pos])     pos=j;    }    temp=pt[pos];   pt[pos]=pt[i];   pt[i]=temp;  temp=p[pos];  p[pos]=p[i];  p[i]=temp;  temp=bt[pos];  bt[pos]=bt[i];  bt[i]=temp;  } wt[0]=0; for(i=1;i<n;i++) {  wt[i]=0;  for(int j=0;j<i;j++)  wt[i]+=bt[j]; } Sys

Round Robin Scheduling Algorithm Program in Java

Image
This is the program for Round robin Scheduling. program: import java.util.Scanner; class roundrobin_sch for (i = 0; i < n; i++) { {  public static void main(String args[])  {   Scanner sc=new Scanner(System.in);   System.out.println("Enter the number of processes:");   int n=sc.nextInt();   int p[]=new int[n];   int bt[]=new int[n];   int wt[]=new int[n];   int tat[]=new int[n];   int fbt[]=new int[n];   System.out.println("Enter the quantum time:");   int qt=sc.nextInt();   System.out.println("Enter the burst times:");   int gc=0,i,j,tbt=0;   for(i=0;i<n;i++)    {     p[i]=i+1;     bt[i]=sc.nextInt();      fbt[i]=bt[i];     tbt+=bt[i]; }  while(tbt>0)   {    for (i = 0; i < n; i++) { if (bt[i] > qt) { bt[i] -= qt;tbt-=qt; System.out.println("p"+p[i]+":"+gc+"-"+(gc+qt));gc+=qt; for (j = 0; j < n; j++) { if ((j != i) && (bt[j] != 0)