import java.io.*;
public class convertToPrintString
{ //输入小写转大写,输入大写转小写
public static void main(String[] args) throws IOException
{
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(reader);
System.out.print("Please enter your word:");
String text = input.readLine();
String s = convertString(text); //text为输入文字,S为转换后的文字。
System.out.println(s);
}
public static String convertString(String str)
{
String upStr = str.toUpperCase();
String lowStr = str.toLowerCase();
StringBuffer buf = new StringBuffer(str.length());
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)==upStr.charAt(i))
{
buf.append(lowStr.charAt(i));
}
else
{
buf.append(upStr.charAt(i));
}
}
return buf.toString();
}
}
本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/facepp/archive/2008/02/01/2076828.aspx