Java将一个字符串的大写字母变成小写字母,小写字母变成大写字母

标题日期:2020/1/14 标题功能:将一个字符串的大写字母变成小写字母,小写字母变成大写字母 标题IDE:Intellij IDEA

package test.demo; import java.util.Arrays; public class ChangeLetter { public static void main(String[] args){ String s1 = new String("Hello world"); char[] s2 = s1.toCharArray(); System.out.println(s2); for(int i=0; i.length; i++){ if(Character.isUpperCase(s2[i])){ s2[i] = Character.toLowerCase(s2[i]); } if(Character.isLowerCase(s2[i])){ s2[i] = Character.toUpperCase(s2[i]); } } System.out.println(s2); } }

    推荐阅读