first fit program in java


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 & lt; 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 & lt; 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 & lt; n; i++) {
			if (it & lt; 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 & lt; n; i++) {
			System.out.println("hole" + (i + 1) + "\t\t" + sp[i]);
		}
	}
}

/*

first fit program in java OUTPUT:
Enter Number of Holes
3
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 */

Facing difficulties in understanding the program ?

Ask Your Queries in Comment Box

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *