package p;
import java.io.*;
public class fifo {
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int frames = 3, pointer = 0, fault = 0, reflen, def = 0;
int spaces[];
int reference[];
int mem_layout[][];
System.out.println("Reference String Length: ");
reflen = Integer.parseInt(br.readLine());
reference = new int[reflen];
mem_layout = new int[reflen][frames];
spaces = new int[frames];
for(int j = 0; j < frames; j++)
spaces[j] = 0;
System.out.println("Reference Numbers: ");
for(int i = 0; i < reflen; i++)
{
reference[i] = Integer.parseInt(br.readLine());
}
System.out.println();
for(int i = 0; i < reflen; i++)
{
int search = -1;
for(int j = 0; j < frames; j++)
{
if(spaces[j] == reference[i])
{
search = j;
def++;
break;
}
}
if(search == -1)
{
spaces[pointer] = reference[i];
fault++;
pointer++;
if(pointer == frames)
pointer = 0 ;
}
for(int j = 0; j < frames; j++)
mem_layout[i][j] = spaces[j];
}
for(int i = 0; i < frames; i++)
{
for(int j = 0; j < reflen; j++)
//System.out.printf("%3d ", reference);
System.out.printf("%3d ",mem_layout[j][i]); //ERROR UNDER PRINTF
System.out.println();
}
System.out.println("Fault: " + fault);
System.out.println("Default: " + def);
System.out.println("Page Fault Rate: " + fault + "/" + reflen + " = " + ((double)fault/reflen)*100 + "%" );
}
}
So we are told to continue our work at home. The code is working fine in our computer lab that is using another version of eclipse. Im using a juno and printf doesn't work anymore. Please help the submission is tomorrow i don't know why it doesn't work anymore.
Is juno outdated? I tried doing the eclipse suggestion for removing the error but it produces more error lol :(
In a comment, you say that the error message is this:
The method format(String, Object[])in the type PrintStream is not applicable for the arguments (String, int)
That is odd. However, one possible explanation is that your Eclipse settings have selected a really old version of Java. Prior to Java 1.5, auto-boxing is not supported., and that would prevent the compiler from autoboxing the int
to an Integer
.
Start Eclipse and open up Window>Preferences. Select the Java>Compiler preferences. Look at that the "Compiler compliance level" setting is, and change it to "1.8".
Then use Project>Clean to recompile everything.
You could also change this:
System.out.printf("%3d ", mem_layout[j][i]);
to this:
System.out.printf("%3d ", new Object[]{
Integer.valueOf(mem_layout[j][i])});
which makes the source code compatible with old Java compilers. But that's a poor solution, IMO.
System.out.format();
instead of System.out.printf();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.