public class Student{
private String num;
private String sex;
private String name;
private int age;
public Student(String num,String sex,String name){
this.num=num;
this.sex=sex;
this.name=name;
}
public String getNum(){
return this.num;
}
public String getSex(){
return this.sex;
}
public String getName(){
return this.name;
}
public int getAge(){
return this.age;
}
public void setAge(int age){
this.age=age;
}
public String toString(){
return "My name is %s, I'm %s years old. I'm a %s. My student num is %s";
}
}
public class Test{
public static void main(String[] args){
Student student=new Student("N01","boy","zhangsan");
student.setAge(18);
System.out.priltln(String.format(student.toString(),student.getName(),student.getAge().toString(),student.getSex(),student.getNum()));
}
}
ok啦 就是这样