变了一程序,对结果不解 (初学) 望赐教

Xmas 2002-03-17 11:03:41

import java.io.*;

public class t311
{
public static void main(String args[])
{
int iOut = 0;
char cTemp = ' ';

try
{
System.out.println("Please input chars (end with '#'):");
cTemp = (char)System.in.read();
if(cTemp == '#')
{
System.out.println("No effective data input . End");
System.exit(1);
}
else
{
iOut = (int)cTemp;
System.out.println(iOut);
}
System.out.println((int)cTemp);
cTemp = (char)System.in.read();
System.out.println((int)cTemp);
while(cTemp != '#')
{
iOut = Math.min(iOut, (int)cTemp);
cTemp = (char)System.in.read();
}
}catch(IOException e) {}

System.out.println("The min input character in ASCII is " + (char)iOut);
}

}

Starting application D:\JavaPro\t311.class
Command line: "D:\j2sdk1.4.0\bin\java.exe" -classpath D:\JavaPro t311
The current directory is: D:\JavaPro
Please input chars (end with '#'):
e
101
101
10
d
#
The min input character in ASCII is

Interactive Session Ended

为什么我再用cTemp = (char)System.in.read();的时候没有阻塞程序,并且下面输出的是10?
...全文
54 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
bbyshigl 2002-03-18
  • 打赏
  • 举报
回复
应该把第二次调用的cTemp=(char)System.in.read();去掉,我认为他没什么用,去掉后就不会出错了。仅供参考

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧