首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

字符串中字母大小写互相转化 [java SE]

2012-11-04 
字符串中字母大小写相互转化 [java SE]下面代码中输入字符串中大写字母可以转化为小写,小写却不能换成大写

字符串中字母大小写相互转化 [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();
}
}
}

[解决办法]
楼主的代码逻辑挺喜感的。

热点排行