题解 | #字符串变形#
字符串变形
http://www.nowcoder.com/practice/c3120c1c1bc44ad986259c0cf0f0b80e
import java.util.*;
public class Solution { public String trans(String s, int n) { String[] str = s.split(" ",-1); StringBuilder strb = new StringBuilder(); for(int i = str.length - 1;i >= 0 ; i--){ strb.append(reverse(str[i])); if(i == 0){ break; } strb.append(" "); } return strb.toString(); } // write code here private String reverse(String s){ StringBuilder res = new StringBuilder(); for(char ch : s.toCharArray()){ if(Character.isLowerCase(ch)){ res.append(Character.toUpperCase(ch)); continue; } if(Character.isUpperCase(ch)){ res.append(Character.toLowerCase(ch)); continue; } } return res.toString(); }
}