- public static String convertString(String str){
- char[] arr = str.toCharArray();
- StringBuilder sb = new StringBuilder();
- for(int i =0;i<arr.length;i++){
- if(arr[i]>='A'&&arr[i]<='Z'){
- arr[i]+=32;
- sb.append(arr[i]);
- }else if(arr[i]>='a'&&arr[i]<='z'){
- arr[i]-=32;
- sb.append(arr[i]);
- }else{
- sb.append(arr[i]);
- }
- }
- return sb.toString();
- }
复制代码 |