- import java.io.*;
- class IODemo3
- {
- public static void main(String[] args) throws IOException
- {
- InputStream in = System.in;
- StringBuilder sb = new StringBuilder();
- while (true)
- {
- int ch = in.read();
- if(ch=='\r')
- continue;
- if(ch=='\n'){
- if("over".equals(sb.toString()))
- break;
- else{
- System.out.println(sb.toString());
- sb.delete(0,sb.length());
- }
- }
- else
- sb.append((char)ch);
- }
- }
- }
复制代码 想请问一下这两段代码就最后的else部分不一样,为什么输出结果不同?有无最后一个else不应该都是一样吗?
请各路好手指教~- import java.io.*;
- class IODemo3
- {
- public static void main(String[] args) throws IOException
- {
- InputStream in = System.in;
- StringBuilder sb = new StringBuilder();
- while (true)
- {
- int ch = in.read();
- if(ch=='\r')
- continue;
- if(ch=='\n'){
- if("over".equals(sb.toString()))
- break;
- else{
- System.out.println(sb.toString());
- sb.delete(0,sb.length());
- }
- }
- sb.append((char)ch);
- }
- }
- }
复制代码 |