public class testString {
public static void main(String[] args){
String str = "abcdef123";
System.out.println("遍历字符串:");
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
System.out.print(c + " ");
}
//反转字符串
System.out.println();
System.out.println("字符串反转之后:");
for (int j = str.length()-1; j >= 0; j--) {
char a1 = str.charAt(j);
System.out.print(a1 + " ");
}
}
}
运行结果:
