/*
* 把一个字符串反转输出 “abcde”
*/
public class Test {
public static void main(String[] args) {
String string = "abcde";
char[] charArray = string.toCharArray();
StringBuilder builder = new StringBuilder();
for (int i = charArray.length-1; i >=0; i--) {
System.out.println(charArray[i]);
builder.append(charArray[i]);
}
System.out.println(builder.toString());
System.out.println(builder.reverse().toString());
//定义一个学生数组。
Student[] students = new Student[]{new Student("旺财", 10),new Student("喵喵", 10),new Student("猪猪", 10)};
for (int i = 0; i < students.length; i++) {
StringBuilder builder2 = new StringBuilder();
System.out.println(builder2.append("第")
.append((i+1))
.append("个人的姓名为")
.append(students[i].name)
.append(",年龄是")
.append(students[i].age).toString());
}
}
}
|
|