i have the problem in this program
Expand|Select|Wrap|Line Numbers
- import java.io.*;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.FileReader;
- import java.io.FileNotFoundException;
- import java.util.*;
- import java.awt.*;
- import javax.swing.*;
- public class placement{
- public static void main(String[]args) throws FileNotFoundException
- {
- String internalFragmentation;
- String externalFragmentation;
- int memory,dummycount;
- int process;
- int[] bestfit,worstfit,nextfit,firstfit;
- Scanner iFile= new Scanner(new FileReader("processes.txt"));
- Scanner inFile1= new Scanner(new FileReader("memory.txt"));
- dummycount=0;
- while (inFile1.hasNext())
- {
- memory = inFile1.nextInt();
- dummycount=dummycount+1;
- }
- firstfit =new int [dummycount];
- inFile1.close();
- System.out.println("------For FirstFit algorithm---------");
- inFile1= new Scanner(new FileReader("memory.txt"));
- dummycount=0;
- while (iFile.hasNext())
- {inFile1= new Scanner(new FileReader("memory.txt"));
- process = iFile.nextInt();
- while (inFile1.hasNext())
- {
- memory = inFile1.nextInt();
- if ((memory >=process)&&(dummycount< firstfit.length)&&(firstfit[dummycount]==0))
- {
- firstfit[dummycount]=process;
- System.out.println("memory partition" " " memory " will accomodate process that need" " " +process);
- }
- }
- dummycount++;
- inFile1.close();
- }
- iFile.close();
- System.out.println("------For BestFit algorithm---------");
- nextfit =new int [dummycount];
- //System.out.println("------For NextFit algorithm---------");
- dummycount=0;
- iFile= new Scanner(new FileReader("processes.txt"));
- while (iFile.hasNext())
- {
- process = iFile.nextInt();
- inFile1= new Scanner(new FileReader("memory.txt"));
- while (inFile1.hasNext())
- {
- memory = inFile1.nextInt();
- if ((memory >=process)&&(dummycount< nextfit.length)&&(nextfit[dummycount]==0))
- {
- nextfit[dummycount]=process;
- System.out.println("memory partition" " " memory " will accomodate process that need" " " +process);
- }
- }
- dummycount++;
- }
- System.out.println("dummycount" +" "+dummycount);
- inFile1.close();
- iFile.close();
- System.out.println("------For WorstFit algorithm---------");
- }
- }
iam work at JSDK 1.6
the problem is not result the out put ????
the algorithm is
first fi that said :
allocate the first hole that is big enough .searching can start either at the beginning of the set holes or where the previous first fit search ended.wec can stop searching as soon as we fnd a large enough free hole.
best fit that said :
allocate the smallest hole that is big enough (the block that is the closet in size ). we must search the entire list ,unless the list is kept ordered by size
worst fit that said:
allocate the biggest hole that is big enough (the block that is the closet in size ). we must search the entire list ,unless the list is kept ordered by size
so
i wont to enter the process and saved it on to memory txt
help me