if (yboi > yleftwerh) { out.println("NW"); System.exit(1); 

Does not display in the console NW. How to fix it?

  • Show the entire program code. - post_zeew
  • Maybe System.out.println("NW") ? - Igor Kudryashov

2 answers 2

Use the following PrintWriter constructor (System.out, true)

 import java.io.PrintWriter; public class Main { public static void main(String [] args){ PrintWriter out = new PrintWriter (System.out, true); out.println("Hello!"); } } 
  • Tell me pliz what means true in the second argument of the constructor? - user31238
  • @ user31238, this means autoflush. That is, no need to call the hands flush() after each call print/println (see my answer, there I obviously flush , with the second parameter true this is not necessary) - iksuy
  • Thank you, note - user31238

Judging by the fact that you have written out.println("NW") you use your PrintWriter . To see the content, you need to flush() buffer by calling flush() .

That is, do so:

 out.println("NW"); out.flush(); System.exit(1); 

When using PrintWriter in small training projects, it is convenient to wrap two calls into one method:

 private static PrintWriter out = new PrintWriter(System.out); //...some code... private static void println(Object o){ out.println(o); out.flush(); } 

and call it when needed:

 println("NW"); System.exit(1); 
  • You can file a generalized method, the same thing will happen - user31238