- import java.io.*;
- class TransStreamDemo
- {
- public static void main(String args[]) throws IOException
- {
- //读取转换流
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- //写入转换流
- BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
- String line = null;
- while((line = br.readLine())!=null)
- {
- if("over".equals(line))
- {
- System.exit(1);
- }
- System.out.println("转换前:"+line);
- System.out.println("转换后:"+transf(line));
-
- }
- }
- public static String transf(String str)
- {
- char[] ch=str.toCharArray();
- for(int i=0;i<ch.length;i++)
- {
- if(ch[i]>=65&&ch[i]<=90)
- {
- ch[i]+=32;
- continue;
- }
- if(ch[i]>=97&&ch[i]<=122)
- {
- ch[i]-=32;
- continue;
- }
- }
- return new String(ch,0,ch.length);
- }
- }
复制代码 |