今天想起了之前的一个问题,反写字符串的方法。
1、
public class shouxie {
public static void main(String[] args) {
String str = "abcdefghijklmnopqrstuvwxyz";
int length = str.length();
char[] chars = str.toCharArray();
for(int i = 0 ; i < length / 2 ; i ++){
char temp;
temp = chars[i];
chars[i] = chars[length - 1 -i];
chars[length -1 - i] = temp;
}
System.out.println(chars);
}
}
2、
public class gest {
public static void main(String[] args) {
Scanner str = new Scanner(System.in);
// String str2 = str.next();
char[] str3 = str.next().toCharArray();
List str4 = new ArrayList();
for(int i = 0; i < str3.length; i ++){
str4.add(str3[i]);
}
for (int j = str4.size() - 1; j >= 0; j --){
System.out.print(str4.get(j));
}
}
}
3、
public class gest {
public static void main(String[] args) {
Scanner str = new Scanner(System.in);
// String str2 = str.next();
char[] str3 = str.next().toCharArray();
List str4 = new ArrayList();
StringBuffer str5 = new StringBuffer();
for(int i = 0; i < str3.length; i ++){
str4.add(str3[i]);
}
for (int j = str4.size() - 1; j >= 0; j --){
str5.append(str4.get(j));
}
System.out.print(str5);
}
}
这样就可以了。