本帖最后由 石好强 于 2012-4-14 15:36 编辑
- import java.io.*;
- class ReadIn
- {
- public static void main(String[] args) throws IOException
- {
- InputStream in = System.in;
- StringBuilder sb = new StringBuilder();
- int ch = 0;
- while((ch = in.read())!=-1)
- {
- if(ch=='\r')
- continue;
- if(ch=='\n')
- {
- System.out.println(sb.toString().toUpperCase());
- sb.delete(0,sb.length());
- }
- else
- sb.append((char)ch);
- String s = sb.toString();
- if("over".equals(s)) //此处写成 "over"==s 为什么不行,按说都是比较的字符串的内容啊
- break; //我写的这个和老师写的位置不同,按说这个是在判断回车前边运行,也就是只要输入over 不用回车程序就应该结束。
- //但事实是,还是需要回车才能结束程序。有人能帮忙解释下原因么?
- }
- in.close();
- }
- }
复制代码 2个疑问,都在代码上注释了,希望能给解释下。
|