class Echo1
{
Echo1(InputStream in) throws Exception
{
int b;
while ((b = in.read()) != -1)
{
System.out.print((char) b);
}
in.close();
}
public static void main(String[] args) throws Exception
{
new Echo1(System.in);
}
}
如果我不用构造方法,那这个程序应该怎么改呢?
看不懂键盘的数据究竟存在哪里了?从键盘上写不是用到写操作吗?不是应该用到OutputStream,为什么这个程序没有?
如果只在主方法中完成,怎么办呢?
追答public class Echo1
{
public static void main(String[] args) throws Exception
{
InputStream in = System.in;
int b;
while ((b = in.read()) != -1)
{
System.out.print((char) b);
}
in.close();
}
}