java - Printing additional line when using System.in.read() -
public class dwdemo { public static void main(string args[]) throws java.io.ioexception { char ch; { system.out.print("press key followed enter: "); ch = (char) system.in.read(); } while (ch != 's'); } } trying learn java. it's simple function result is
press key followed enter: d press key followed enter: press key followed enter: g press key followed enter: press key followed enter: e press key followed enter: press key followed enter: f press key followed enter: press key followed enter: s system print "press key followed enter:" twice in intellij , in eclipse print 3 times.
please help!
since reading char console. every "enter" == '\n' taken character. (char)system.in.read() taking 2 chars , loop gets incremented every character reads , "enter".
Comments
Post a Comment