Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java System.out.println()不';i don’在for循环中,我不能像我所希望的那样工作_Java_For Loop_Println - Fatal编程技术网

Java System.out.println()不';i don’在for循环中,我不能像我所希望的那样工作

Java System.out.println()不';i don’在for循环中,我不能像我所希望的那样工作,java,for-loop,println,Java,For Loop,Println,首先,我很抱歉我的英语不好。我在讲我语言的论坛上写下了我的问题。但我没有得到答案。我希望你能帮助我 当我编写for循环时,循环结束后,System.out.println()或JTextArea.setText()命令开始工作。我的部分代码: for(int pixelCount = 0;pixelCount<pixelLength;pixelCount++){ System.out.println("Progress..:"+pixelCount+"/"+pixelLength);

首先,我很抱歉我的英语不好。我在讲我语言的论坛上写下了我的问题。但我没有得到答案。我希望你能帮助我

当我编写for循环时,循环结束后,
System.out.println()或
JTextArea.setText()
命令开始工作。我的部分代码:

for(int pixelCount = 0;pixelCount<pixelLength;pixelCount++){

  System.out.println("Progress..:"+pixelCount+"/"+pixelLength);



  int x = pixelCount%Image.getWidth();
  int y = pixelCount/Image.getWidth();
  if(isChange==1){
    if(new Color(Image.getRGB(x, y)).getRed()%2==0){
        Image.setRGB(x, y,new Color(new Color(Image.getRGB(x, y)).getRed()+1,
                                    new Color(Image.getRGB(x, y)).getGreen(),
                                    new Color(Image.getRGB(x, y)).getBlue(),
                                    new Color(Image.getRGB(x, y)).getAlpha()).getRGB());}
}

for(int pixelCount=0;pixelCount打印后调用
System.out.flush()
,或使用
System.err.println


System.out
是一个缓冲流,在缓冲区已满、刷新时或系统认为有用的其他时间打印。
System.err
是非缓冲流,也是调试和诊断信息(如进度信息)的首选流。

调用
System.out.flush()
打印后,或使用
System.err.println


System.out
是一个缓冲流,在缓冲区已满、刷新时或系统认为有用的其他时间打印。
System.err
是无缓冲的,也是调试和诊断信息(如进度信息)的首选流。

使用System.our.flush()Erwin Bolwidt已经提到了。输出的方式很大程度上取决于你使用的OS(和终端)的类型。例如对于*nix系统,你可以考虑类似于诅咒的某种库(它最初是一个C库,但我确信有一些java实现)。Erwin Bolwidt已经提到了,输出的方式很大程度上取决于你使用的OS(和终端)的类型。例如,对于*nix系统,你可以考虑类似于诅咒的某种库(它最初是一个C库,但我确信有一些java实现)。.

可能重复@Guy没有同步或多线程,但在OP的代码中,因此您的重复不相关here@ErwinBolwidt可能会有更精确的副本,但其想法是,
System.out.println
不同步,这就是为什么只有在循环结束后才会显示输出。@Guy没有thre涉及到ading。System.out.println未同步的事实与OP的问题完全无关。@Guy的可能副本没有同步或多线程,但在OP的代码中,因此您的副本不相关here@ErwinBolwidt可能会有更精确的副本,但想法是
System.out.println
未同步,这就是为什么只有在循环结束后才会显示输出。@没有涉及线程。System.out.println未同步的事实与OP的问题毫无关系。感谢您的评论。我尝试了两种方法。但仍然不起作用。只有System.err.println()命令是红色的。谢谢你的评论。我两个都试过了。但仍然不起作用。只有System.err.println()命令是红色的。