program to implement Round Robin algorithm in JAVA


import java.io.*;
class RRobin
{
public static void main(String[] args)throws IOException
{
    BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
    int np,q,i,j,k;
    int s=0;
    System.out.println("ENTER THE NUMBER OF PROCESSES");
    np=Integer.parseInt(b.readLine());
    int bu[]=new int[np+1];
    int p[]=new int[np+1];
    System.out.println("ENTER THE QAUNTUM NUMBER");
    q=Integer.parseInt(b.readLine());
    System.out.println("ENTER THE BURST TIME OF EACH PROCESS");
    for(i=0;i<np;i++)
    {
        bu[i]=Integer.parseInt(b.readLine());
    }
    for(k=0;k<np;k++)
    {
        s=bu[k]+s;
    }
    s=s/q;
    for(k=0;k<s; k++)
    {
        for(i=0;i<np;i++)
        {
            if(bu[i]!=0)
            {
                System.out.println("PROCESS "+i+" IS EXECUTING");
                for(j=0;j<q;j++)
                {
                    System.out.println("..");
                    bu[i]--;
                }
            } 
        }
    }
}
}



***** OUTPUT *****

C:\>javac RRobin.java

C:\>java -cp . RRobin
ENTER THE NUMBER OF PROCESSES
3
ENTER THE QAUNTUM NUMBER
2
ENTER THE BURST TIME OF EACH PROCESS
3
4
2
PROCESS 0 IS EXECUTING
..
..
PROCESS 1 IS EXECUTING
..
..
PROCESS 2 IS EXECUTING
..
..
PROCESS 0 IS EXECUTING
..
..
PROCESS 1 IS EXECUTING
..
..
PROCESS 0 IS EXECUTING

2 comments :

  1. for(k=0;k<np;k++)
    {
    s=bu[k]+s;
    }
    s=s/q; please could you tell me what this for loop is doing ?

    ReplyDelete
  2. i want simple code jave about Round Robin Scheduling Algorithm by setter & getter ...

    please answer me !!

    ReplyDelete