public class Test extends Thread { public static void main(String[] args) { String tString = "this is a demo string"; String tString2 = ""; for (int i = 0; i < tString.length(); i++) { tString2 += tString.charAt(tString.length() - 1 - i); } System.out.println(tString2); }} 但是我没有明白你说的子串demo顺序不变?是什么意思。
我的简单实现 public class test { /** * @description : TODO * @param args * @returntype : void * @throws : */ public static void main(String[] args) { // TODO Auto-generated method stub test.testStringVert(); }
public static void testStringVert(){ String strBef = new String("this is a demo string"); String[] strArr = strBef.split(" "); int len = strArr.length; String strAft = new String(""); for(int index = (len-1) ; index>=0;index--){ if(strArr[index].endsWith("demo")){ strAft += strArr[index]; }else{ strAft += testAAA(strArr[index]); } strAft += " "; }
System.out.println(strAft); }
public static String testAAA(String str){ byte[] strArr = str.getBytes(); String ret = new String(); for(int index=(strArr.length-1);index>=0;index--){ ret += String.valueOf((char)strArr[index]); } return ret; }}
public static void main(String[] args) {
String tString = "this is a demo string";
String tString2 = "";
for (int i = 0; i < tString.length(); i++) {
tString2 += tString.charAt(tString.length() - 1 - i);
}
System.out.println(tString2);
}}
但是我没有明白你说的子串demo顺序不变?是什么意思。
public class test { /**
* @description : TODO
* @param args
* @returntype : void
* @throws :
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
test.testStringVert(); }
public static void testStringVert(){
String strBef = new String("this is a demo string");
String[] strArr = strBef.split(" ");
int len = strArr.length;
String strAft = new String("");
for(int index = (len-1) ; index>=0;index--){
if(strArr[index].endsWith("demo")){
strAft += strArr[index];
}else{
strAft += testAAA(strArr[index]);
}
strAft += " ";
}
System.out.println(strAft);
}
public static String testAAA(String str){
byte[] strArr = str.getBytes();
String ret = new String();
for(int index=(strArr.length-1);index>=0;index--){
ret += String.valueOf((char)strArr[index]);
}
return ret;
}}