编写程序,从键盘接收一个字符串,对字符串中的字母进行大小写互转(大写字母转成小写,小写字母转成大写)。 
import java.io.*; 
class Text5 
{ 
        public static void main(String[] args) throws IOException 
        { 
                InputStream in = System.in; 
                StringBuffer sbuf = new StringBuffer(); 
                for(int x=in.read(); ; x=in.read()) 
                { 
                        if(x=='\r') 
                                continue; 
                        else if(x=='\n') 
                                break; 
                        else 
                        { 
                                if(x<='z'&&x>='a') 
                                        sbuf.append((char)(x-32)); 
                                else if(x<='Z'&&x>='A') 
                                        sbuf.append((char)(x+32)); 
                                else 
                                        sbuf.append((char)x); 
                        } 
                } 
                System.out.println(sbuf.toString()); 
        } 
} 
 
中间for循环为甚写成这样,程序不会停止? 
import java.io.*; 
class Text5 
{ 
        public static void main(String[] args) throws IOException 
        { 
                InputStream in = System.in; 
                StringBuffer sbuf = new StringBuffer(); 
                for(int x=in.read(); x!=-1 ; x=in.read()) 
                { 
                        if(x<='z'&&x>='a') 
                                sbuf.append((char)(x-32)); 
                        else if(x<='Z'&&x>='A') 
                                sbuf.append((char)(x+32)); 
                        else 
                                sbuf.append((char)x); 
                } 
                System.out.println(sbuf.toString()); 
        } 
} 
当读取完键盘录入的数据,read()方法返回的是什么? |