java - System.in.read() behaviour i can't explain -


class e92stringdemo {   public static void main(string args[]) throws java.io.ioexception {        string strobj1 = "first string";        for(int i=0;i<strobj1.length();i++) {          system.out.print(strobj1.charat(i));         system.in.read(); //just pause execution till press enter key        }    } } 

i want output come like:

f r s t... 

but output coming like:

f ir st s tr in g 

i not sure how come 2 characters getting displayed in 1 line every press of enter key(\n)?

i running windows 8 , using command prompt run file using javac.

enter on windows generates 2 characters (crlf) whereas read() consumes 1 of them. must consume 2 characters desired behaviour. add system.in.read() , see.

the following explains generation , consumption of characters when press enter. 13 represents cr , 10 represents lf. f 13i10r 13s10t 13 10s 13t10r 13i10n 13g10


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -