11-新建一个学生类,然后使用java来数组存起来
public class Student {
String name;
int age;
boolean gender;
public Student(String name , int age , boolean gender){
this.name = name;
this.age = age;
this.gender = gender;
}
}
--------
public class demo007 {
public static void main(String[] args) {
/*
这是一个测试类
*/
// 存储一个学生的信息
Student stu = new Student("张三",18,true);
// 存储所有学生的信息
Student[] stus = new Student[5]; //初始化 数组长度为5 数据为null
stus[0] = new Student("李四",19,false);
System.out.println(stus[0].name);
Student[] stu1 = new Student[]{
new Student("王五",22,true),
new Student("王五2",32,false)
};
//可以简写掉 new Student[]
for (Student item :stu1) {
System.out.println(item.name);
}
}
}