java - BufferedReader / Scanner Last Line Reading Issue -
while solving problem @ hacker-rank facing issue scanner/bufferedreader unable read last. input provided them like
10 abcdefghijk 2 r 1 2 w 3 4
so both scanner/bufferedreader unable read last line. if input code seems work fine.
10 abcdefghijk 2 r 1 2 w 3 4
(end of input)
public class scannertest { public static void main(string[] args) { // todo auto-generated method stub scanner input = new scanner(system.in); int len = input.nextint(); input.nextline(); string inputstring = input.nextline(); int qc = input.nextint(); input.nextline(); system.out.println(); system.out.println(len + inputstring + qc); for(int i=0;i<qc;i++){ string l = input.next(); int le = input.nextint(); int ri = input.nextint(); input.nextline(); system.out.println(l+le+ri); } input.close(); } }
here sample code using. know need \r or\n @ end of line readline scanner / bufferedreader. can provide solution issue input comes system predefined.
bufferedreader
read last line if not end in line break. system.in
culprit, own line buffering. native system thing: suppose pressed couple of backspaces change last number...
Comments
Post a Comment