First Fit Algorithm > Java Program

Computer Organization and Architecture

First Fit Algorithm > Java Program

import java.io.*;
class firstfit 

public static void main(String args[])throws IOException
{

int n,i,it;
DataInputStream in=new DataInputStream(System.in);
System.out.println("Enter Number of Holes");
n=Integer.parseInt(in.readLine());
int sp[]=new int[n];
for(i=0;i<n;i++)
{
System.out.println("Enter size of Hole"+(i+1));
sp[i]=Integer.parseInt(in.readLine());
}
System.out.println("Before Insertion of new process");
System.out.println("hole\t\tsize");
for(i=0;i<n;i++)
{
System.out.println("hole"+(i+1)+"\t\t"+sp[i]);
}
System.out.println("enter new process size to insert");
it=Integer.parseInt(in.readLine());
for(i=0;i<n;i++)
{
if(it<sp[i]) { sp[i]=sp[i]-it; break;
}
}
System.out.println("After Insertion of new process");
System.out.println("hole\t\tsize");
for(i=0;i<n;i++)
{
System.out.println("hole"+(i+1)+"\t\t"+sp[i]);
}
}
}
/*OUTPUT:
Enter Number of Holes 

Enter size of Hole1 
10 
Enter size of Hole2 
20 
Enter size of Hole3 
30 
Before Insertion of new process 
hole  size 
hole1  10 
hole2  20 
hole3  30 
enter new process size to insert 
15 
After Insertion of new process 
hole  size 
hole1  10 
hole2  5 
hole3  30
*/

Comments

Popular posts from this blog

Intermediate Code Generation > C Program