import java.util.*;public class Solution {/*** 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可** * @param s string字符串 * @param n int整型 * @return string字符串*/public String trans (String s, int n) {// write code hereif(n == 0) return null;StringBuffer res = new StringBuffer();for(int i = 0; i < n; i++){char c = s.charAt(i);if('A' <= c && c <= 'Z'){res.append((char)(c - 'A' + 'a'));}else if('a' <= c && c <= 'z'){res.append((char)(c - 'a' + 'A'));}else{res.append(c);}}res.reverse();//整体翻转for(int i = 0; i < n; i++){int j = i;while(j < n && res.charAt(j) != ' ')j++;String temp = res.substring(i,j);StringBuffer buffer = new StringBuffer(temp);temp = buffer.reverse().toString();res.replace(i,j,temp);i = j;}return res.toString();}
}
大小写转化
整体翻转,再把单词翻转