java中如何将每个单词的字母反转,就是将"To be or not to be "变成“oT eb ro ton ot eb”

public static void main(String[] args){
  String s = "To be or not to be ";   
  String[] ss = s.split(" ");
  StringBuilder sb = new StringBuilder();
  for (String temp : ss) {
   StringBuilder sbtmp = new StringBuilder(temp);
   sbtmp.reverse();
   sb.append(sbtmp).append(" ");
  }
  System.out.println(sb.toString());
 }

你可能感兴趣的:(面试题)