日期:2014-05-20  浏览次数:20649 次

字符串中字母大小写相互转化 [java SE]
下面代码中输入字符串中大写字母可以转化为小写,小写却不能换成大写,为什么?
import java.io.*;
public class Exec5_1
{
public static void main(String[] args)
{
try
{
System.out.println("请输入字符串:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine();
char a[]=s.toCharArray();
for(int i=0;i<a.length;i++)
{
if(Character.isLowerCase(a[i]))
{
a[i]-=32;//出问题的地方
}
if(Character.isUpperCase(a[i]))
{
a[i]+=32;
}
}
String str=new String(a);
System.out.println(str);
}
catch(IOException e)
{
e.printStackTrace();
}
}
}

------解决方案--------------------
楼主的代码逻辑挺喜感的。