为何输入"bye"时,程序并没有结束?
class TestString {
public static void main (String[] args) {
int ch = 0;
byte[] array1 = new byte[1024];
int pos = 0;
String str = null;
System.out.println("please input your char:");
while(true) {
try{
ch = System.in.read();
}
catch(Exception ex) {}
switch(ch) {
case '\r':
break;
case '\n':
{
str = new String(array1,0,pos);
pos = 0;
System.out.println(str);
if(str.equalsIgnoreCase("bye"))
return;
}
default:
array1[pos++] = (byte)ch;
}
}
}
}
|
|