-
Notifications
You must be signed in to change notification settings - Fork 0
/
fifo_page.java
73 lines (70 loc) · 1.26 KB
/
fifo_page.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.io.*;
import java.util.*;
public class fifo_page
{
public static int row;
public static int check(int pt[],int no)
{
for(int i=0;i<row;i++)
{
if(pt[i]==no)
{
return 1;
}
}
return 0;
}
public static void display(int pt[])
{
System.out.println("Queue Status:- ");
for(int i=0;i<row;i++)
{
System.out.print(pt[i]+"\t");
}
System.out.println();
}
public static void main(String args[]) throws IOException
{
int no,fault=0;
Scanner sc=new Scanner(System.in);
System.out.println("Please enter the number of rows in page table:- ");
row=sc.nextInt();
int pt[]=new int[row];
System.out.println("Please enter the total number of pages:- ");
no=sc.nextInt();
int pgarr[]=new int[no];
System.out.println("Please enter the page information:-");
for(int i=0;i<no;i++)
{
pgarr[i]=sc.nextInt();
}
int k=0,z,j=0;
while(k<row)
{
z=check(pt,pgarr[j]);
if(z==0)
{
pt[k]=pgarr[j];
k=k+1;
display(pt);
}
j=j+1;
}
fault=fault+1;
for(int i=j;i<no;i++)
{
z=check(pt,pgarr[i]);
if(z==0)
{
for(int h=0;h<row-1;h++)
{
pt[h]=pt[h+1];
}
pt[row-1]=pgarr[i];
display(pt);
fault=fault+1;
}
}
System.out.println("Total Page Faults:- "+fault);
}
}