怎么用java把 To be or not to be变成eb ot ton ro eb oT

第一种:
String str = "To be or not to be ";
StringBuffer sb = new StringBuffer(str);
System.out.println(str+"反转"+sb.reverse());
第二种:
 String s=" To be or not to be";
 String result="";
 for(int i = s.length() - 1; i >= 0; i--){
 result += s.charAt(i); 
 }
 System.out.println(result);


 
  
 
  

你可能感兴趣的:(编程小题)