java - Displaying Output Not as Expected -


for following program expecting output as

enter value : 3 entered 3 

but not getting output, instead in output java expecting input without displaying "enter value". if enter value display output as

3 enter value : entered 3. 

here code:

    import java.io.*;     // system.in object of inputstream - byte stream      class consoleinputdemo{         public static void main(string args[]) throws ioexception{             bufferedreader consoleinput = new bufferedreader(new inputstreamreader(system.in)); // convert byte stream character stream             printwriter consoleoutput = new printwriter(system.out);               consoleoutput.println("enter value : ");             int c= consoleinput.read();             consoleoutput.write("you entered " + c);             consoleinput.close();             consoleoutput.close();          }     } 

consoleoutput.println didn't print until close(). use

 system.out.println("enter value :  ") 

instead of

consoleoutput.println("enter value : "); 

or close consoleouput if want view text.

 consoleoutput.print("enter value : ");  consoleoutput.close(); 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -