- class Test
- {
- public static void main(String[] args)throws IOException
- {
- BufferedReader bufr =
- new BufferedReader(new InputStreamReader(System.in));
- String str = bufr.readLine();
- String s = change(str);
- System.out.println(s);
- }
- public static String change(String str)
- {
- StringBuilder sb = new StringBuilder();
- char[] chs = str.toCharArray();
-
- for(char c : chs)
- {
- if(c>='a' && c<='z')
- //sb.append(String.valueOf(c).toUpperCase());
- //sb.append(Character.toString(c).toUpperCase());
- c = Character.toUpperCase(c);
- //sb.append(String.valueOf(c));
- if(c>='A' && c<='Z')
- //sb.append(String.valueOf(c).toLowerCase());
- //sb.append(Character.toString(c).toLowerCase());
- c = Character.toLowerCase(c);
- //sb.append(String.valueOf(c));
- }
- //return sb.toString();
- return new String(chs);
- }
- }
复制代码
如上,现在的代码运行的话,大小写是转换不了的,如果换成注释的内容,就可以,现在疑惑的是,为什么现在不行呢,是因为字符数组里字符的值不能重新赋值吗? |
|