import java.io.*;
public class In {
public static void main(String[] args)
{
char[] input;
int count=0;
int counter=0;
input=new char[20];
try {
while(count<20&&(input[count++]=(char)System.in.read())!='\n') {
System.out.write(input[count-1]);
System.out.write('#');
counter++;
}
}
catch (IOException e) {
e.printStackTrace();
}
System.out.println("Counter="+counter);
String output=new String(input);
System.out.println(output);
}
}
程序的意思很明白,一看就懂。但是运行始终不是想象那样。
比如:(前面数字为行号)
输入:1.hello
输出:1.hello //此处为cmd回显
2.#Counter=6 //为什么while的第一句没有输出,输出到下面去了。。还有就是counter为什么等于6
3.hello //此处应该是while循环的输出吧,但是为什么到最后来了?
4.\n //此处应该是最后一句,输出output。但是为什么成了空白符了呢?
5.\n //此处应该是cmd每次执行都会有的一个换行操作吧。。
理想中的输出应该是:
1.hello
2.h#e#l#l#o#Counter=5
3.hello
4.\n