简体   繁体   English

printf(“%3d,…)在eclipse juno上不起作用

[英]printf("%3d, …) not working on eclipse juno

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. 该代码在使用另一个版本的eclipse的计算机实验室中可以正常工作。 Im using a juno and printf doesn't work anymore. 我正在使用juno和printf不再起作用。 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) 类型PrintStream的方法format(String,Object [])不适用于参数(String,int)

That is odd. 真奇怪 However, one possible explanation is that your Eclipse settings have selected a really old version of Java. 但是,一种可能的解释是您的Eclipse设置选择了一个非常旧的Java版本。 Prior to Java 1.5, auto-boxing is not supported., and that would prevent the compiler from autoboxing the int to an Integer . 在Java 1.5之前,不支持自动装箱。这将阻止编译器将int自动装箱为Integer

Start Eclipse and open up Window>Preferences. 启动Eclipse并打开Window> Preferences。 Select the Java>Compiler preferences. 选择Java> Compiler首选项。 Look at that the "Compiler compliance level" setting is, and change it to "1.8". 查看“编译器符合级别”设置,并将其更改为“ 1.8”。

Then use Project>Clean to recompile everything. 然后使用Project> Clean重新编译所有内容。


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. 这使得源代码与旧的Java编译器兼容。 But that's a poor solution, IMO. 但这是一个糟糕的解决方案,IMO。

  • Try System.out.format(); 试试System.out.format(); instead of System.out.printf(); 而不是System.out.printf();
  • Try installing another version of Eclipse that they're using at labs 尝试安装他们在实验室使用的另一个版本的Eclipse
  • And please, write us what error/exception is Eclipse showing 并且,请写信给我们Eclipse显示什么错误/异常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM