title: Java - the difference between BufferedWriter.write() and System.out.println()?
body: <p>I have been trying to solve an algorithm problem called Chebyshev's Theorem(<a href="https://www.acmicpc.net/problem/4948" rel="noreferrer">https://www.acmicpc.net/problem/4948</a>)</p>
  
  <p>And I got an interesting situation. I haven't figured out the difference between yet. And I hope I can find the answer here.</p>
  
  <p>And this is my code:</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.BufferedWriter;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.OutputStreamWriter;
  import java.util.ArrayList;
  
  public class Solution {
      public static void main(String[] args)  throws IOException {
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
  
          while(true){
              System.out.println("start!!");
              int input = Integer.parseInt(br.readLine());        
              if(input == 0){
                  break;
              }
              int ddable = 2*input;
              int answer = 0;
              ArrayList&lt;Integer&gt; base = new ArrayList&lt;&gt;();
  
              if(input == 1){
                  answer = 1;
              }else { 
                  System.out.println("It is not 1");
                  for(int i = 2 ; i &lt;= ddable ; i++ ){
                      base.add(i);
                  }
  
                  for ( int i = 2 ; i &lt;= ddable ; i++ ){
                      for ( int j = 2 ; i*j &lt;=ddable ; j++){
                          if(base.contains(new Integer(i*j))){
                              base.remove(new Integer(i*j));
                              System.out.println(i*j+"removed");
                          }
                      }
                  }
                  int count = 0;
                  for ( int i = input ; i &lt;= ddable ; i++){
                      if(base.contains(new Integer(i))){
                          count++;
                      }
                  }
                  answer = count;
              }
              System.out.println("syso: "+answer);
              bw.write("bw: "+answer);
          }
          bw.flush();
          br.close();
          bw.close();
      }
  }
  </code></pre>
  
  <p>And this is my result:</p>
  
  <p><a href="https://i.stack.imgur.com/xS7Dy.png" rel="noreferrer"><img src="https://i.stack.imgur.com/xS7Dy.png" alt="enter image description here"></a></p>
  
  <p>As you can see, this just shows the result of 'System.out.prinln()'.</p>
  
  <p>What's the reason?</p>