public static void main(String[] args) throws IOException {
InputStream is = System.in;
StringBuilder sb = new StringBuilder();
while (true) {
int by = is.read();
if (by == '\r') {
continue;
}
if (by == '\n') {
if ("over".equals((char) by)) { // 我是这样定义的结束条件 但是当输入"over" 时程序不会结束 ?
break;
}
System.out.println(sb.toString());
sb.delete(0, sb.length());
} else {
sb.append((char) by);
}
}
}
作者: 夏振博 时间: 2013-2-15 12:48
换个比较条件 if ("over".equals(sb.toString())) 你那个判断条件是存之前的单个字符跟"over"比较作者: 冯佩 时间: 2013-2-15 13:05
public class Test
{
public static void main(String[] args)throws IOException
{
InputStream is = System.in;
StringBuilder sb = new StringBuilder();
while (true)
{
int by = is.read();
if('o'==by)
break;
if (by == '\r')
continue;