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

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -