public class test
{
static public void main(String[] args)
throws Exception
{
System.out.print("please input user name: ");
int c = System.in.read();
System.out.println();
if(c == -1)
System.out.println("Ctrl-C has been pressed!");
System.out.print(c + " ");
do
{
c = System.in.read();
System.out.print(c + " ");
}
while(c != 10);
System.out.println();
}
}
1, System.in.read() would not return until you pressed RETURN or Ctrl-C which also termninates program as well;
2, You can edit the line before press RETURN, program will never see those changes;
3, Ctrl-C will cause System.in.read() returns -1 no matter how many other chars you have inputed;
4, A RETURN carries two int values 13 and 10, so you can determinate an input stops here. Usually 13 and 10 are discarded, but you have to read them out from System.in.
{
static public void main(String[] args)
throws Exception
{
System.out.print("please input user name: ");
int c = System.in.read();
System.out.println();
if(c == -1)
System.out.println("Ctrl-C has been pressed!");
System.out.print(c + " ");
do
{
c = System.in.read();
System.out.print(c + " ");
}
while(c != 10);
System.out.println();
}
}
1, System.in.read() would not return until you pressed RETURN or Ctrl-C which also termninates program as well;
2, You can edit the line before press RETURN, program will never see those changes;
3, Ctrl-C will cause System.in.read() returns -1 no matter how many other chars you have inputed;
4, A RETURN carries two int values 13 and 10, so you can determinate an input stops here. Usually 13 and 10 are discarded, but you have to read them out from System.in.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货