1.除2判中法:
public String orderDesc(String str){ byte [] bytes = str.getBytes(); for ( int i = 0; i < bytes.length / 2 ; i++) { Byte b = bytes [i] ; bytes [i] = bytes [bytes.length - 1 -i ] ; bytes [bytes.length - 1 -i ] = b ; } return new String (bytes) ; }
2.String类的toCharArray();
public static String orderDesc(String str){ char[] charArray = str.toCharArray(); String newStr = ""; for (int i=charArray.length-1; i>=0; i--){ newStr += charArray[i]; } return newStr; }
时间: 2024-10-10 14:17:39