add System.out.flush() to flush I/O buffer